Pierre L
2009-Jan-25 23:08 UTC
[ActiveRecord] How to automatically bind, for example, :rows with Row or :user_id with User ?
Hello, Imagine that I have the two following models : class A < ActiveRecord::Base belongs_to :b, :foreign => :fkey end class B < ActiveRecord::Base end Is it possible to retrieve both classes A and B and that column fkey is pointing to table B ? In other words, if I give :a and :fkey, how to obtain the class A and the fact that ''fkey'' is a foreign key pointing to table ''B'' ? I am almost sure that AR can do that, but this is not well-documented, and source-code is a bit obsucated... Thank you in advance, Pierre L. --~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2009-Jan-26 12:55 UTC
Re: [ActiveRecord] How to automatically bind, for example, :rows with Row or :user_id with User ?
On 25 Jan 2009, at 23:08, Pierre L wrote:> > Hello, > > Imagine that I have the two following models : > class A < ActiveRecord::Base > belongs_to :b, :foreign => :fkey > end > > class B < ActiveRecord::Base > end > > Is it possible to retrieve both classes A and B and that column fkey > is pointing to table B ? In other words, if I give :a and :fkey, how > to obtain the class A and the fact that ''fkey'' is a foreign key > pointing to table ''B'' ?If you''re looking to introspect what associations have been setup then you''d want to look at A.reflections. Fred> > I am almost sure that AR can do that, but this is not well-documented, > and source-code is a bit obsucated... > > Thank you in advance, > Pierre L. > > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
Pierre L
2009-Jan-27 19:32 UTC
Re: [ActiveRecord] How to automatically bind, for example, :rows with Row or :user_id with User ?
Thank you ! On 26 jan, 13:55, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 25 Jan 2009, at 23:08, Pierre L wrote: > > > > > Hello, > > > Imagine that I have the two following models : > > class A < ActiveRecord::Base > > belongs_to :b, :foreign => :fkey > > end > > > class B < ActiveRecord::Base > > end > > > Is it possible to retrieve both classes A and B and that column fkey > > is pointing to table B ? In other words, if I give :a and :fkey, how > > to obtain the class A and the fact that ''fkey'' is a foreign key > > pointing to table ''B'' ? > > If you''re looking to introspect what associations have been setup then > you''d want to look at A.reflections. > > Fred > > > > > > > I am almost sure that AR can do that, but this is not well-documented, > > and source-code is a bit obsucated... > > > Thank you in advance, > > Pierre L.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---