Forum: Ruby on Rails [ActiveRecord] How to automatically bind, for example, :rows with Row or :user_id with User ?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
5ebc4a174dc36f92f35f94355fecbc11?d=identicon&s=25 Pierre L (Guest)
on 2009-01-26 13:51
(Received via mailing list)
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.
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2009-01-26 13:56
(Received via mailing list)
On 25 Jan 2009, at 23:08, Pierre L wrote:

>
> 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
5ebc4a174dc36f92f35f94355fecbc11?d=identicon&s=25 Pierre L (Guest)
on 2009-01-27 20:33
(Received via mailing list)
Thank you !
This topic is locked and can not be replied to.