[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

need help with STI model and auto reference.

somekool

4/16/2006 3:01:00 AM

here is my models

class Letter << AR
belongs_to :word
end
class LetterA << Letter
end
class LetterB << Letter
end
class LetterC << Letter
end
class LetterD << Letter
end

class Word << AR
has_many :letters
end

ok, this looks simple enough right ?

now, when I want to create a letter C for a word. i can do.

w = Word.new

# first: type is illegal here. :word_id will automatically be filled.
w.letters.create(:name => 'none', :type => 'LetterA')

# second: type gets auto filled, but word_id does NOT
LetterA.create(:word_id => w[:id], :name => 'none')

HOW DO I GET BOTH AUTO FILLED ? type and word_id ????

can't think of a way.

thanks