Zirael wrote:> Hi,
>
> I have two database tables
> Briefly:
> Projects
> -type
> -designer_id
> -check_designer_id
> - ...
> Designers
> -name
> -...
>
> I want to create two foreign keys in Projects table and both with
> the same Designer table.
>
> How should I deal with that problem, I want to use ActiveRecords.
> Is it possible?
Yes, Serving from memory (at work taking a break), look at belongs_to
:foreign_key to specify alternate/extra foreign key relationships..
class Project < ActiveRecord::Base
belongs_to :designer, :foreign_key=>"designer_id"
belongs_to :designer, :foreign_key=>"some_other_foreign_key_id"
end
class Designer < ActiveRecordBase
has_many :projects, :foreign_key=>"designer_id"
has_many :projects, :foreign_key=>"some_other_foreign_key_id"
end
Designer.find(:first).some_other_foreign_keys.each { etc..... }
hope this helps
ilan
--
Posted via http://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-/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
-~----------~----~----~----~------~----~------~--~---