Im wondering how I can define the following table structure from a legacy DB in Rails. If I have three tables, tables A, B and C. And in table A, I have an integer field, call it ''B_or_C_id'' and also an integer field in table A called ''you_must_use_C'' which, if -1 means A.B_or_C_id = C.id and if 0 means A.B_or_C_id = B.id How in the world do you define this in ActiveRecord in terms of ''belongs_to,'' and ''has_many'' Thanks, Ralph Vince --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
igotimac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Nov-02 18:11 UTC
Re: Have you ever seen this table structure?
It looks like you may need to have a base class A and 2 subclasses of A corresponding to 2 types. Something like AWithB and AWithC, which both subclass A. (and put all the has_many and belongs_to stuff that relates to C and B in the subclasses) --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
It seems I should be able to use ''conditions'' ion the has_many and belongs to, yes? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---