need help with STI model and auto reference.

S

somekool

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top