Ilan, Mcq and TrueFalse descend from question and not choice. The correct structure is below.
app/models/choice.rb class Question < ActiveRecord::Base end app/models/question.rb class Question < ActiveRecord::Base self.abstract_class = true end class Mcq < Question;end class TrueFalse < Question;end app/models/mcq.rb class Mcq < Question has_many choices end app/models/true_false.rb class TrueFalse < Question has_many choices end As you can see my question.rb had definitions for all the classes, one abstract and 2 concrete but they didn't have the has_many relation to choices. This relation was present in a different file which was not loaded at the time of calling the method. That was causing the issue. -subbu On Sep 10, 2:08 am, Ilan Berci <[EMAIL PROTECTED]> wrote: > the fact that you had 2 definitions each for your concretes looks to be > your issue.. in order to do this and behave well under rails you will > need exactly 3 files and 3 classes.. > > I am willing to bet that one of your implementations had the choices() > method implemented and the other didn't.. > > app/models/choice.rb > class Choice < ActiveRecord::Base > abstract true > # no need to implement choices here unless you have a default > implementation > end > > app/models/mcq.rb > class Mcq < Choice > def choices > end > end > > app/models/true_false.rb > class TrueFalse < Choice > def choices > end > end > > hth > > ilan > > > > Subbu wrote: > > Looks like I have found one solution. > > > I had 2 definitions for the classes Mcq and TrueFalse, one in separate > > files named mcq.rb and true_false.rb and another definition in the > > file question.rb (the abstract class itself). I had to have these > > definitions in 2 files because otherwise I couldn't call the concrete > > classes directly without first loading the abstract class. But that > > apart, my has_many relation was not in the abstract class file. So it > > was not getting loaded when I issued the find statement on the > > abstract class. But if I issue the find on the concrete class directly > > (without calling the abstract class before) it would've loaded the > > has_many by then and would load the relations properly. Bit tricky. To > > be on the safer side now I have moved all my definitions to the > > abstract class file and keeping the concrete class files empty. > > > -subbu > > -- > Posted viahttp://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---