Monday, October 15, 2012

[Rails] Re: A custom method for models

> belongs_to :destination, :class_name => "Place", :foreign_key =>
> "destination_id"
> belongs_to :departure, :class_name => "Place", :foreign_key =>
> "departure_id"
>

I didn't know anything about ":foreign_key" option.

I put

class Place < ActiveRecord::Base
has_many :flight_names, :foreign_key => :departure_id
has_many :flight_names, :foreign_key => :destination_id
end

class FlightName < ActiveRecord::Base
belongs_to :departure, :class_name => "Place", :foreign_key =>
:departure_id
belongs_to :destination, :class_name => "Place", :foreign_key =>
:destination_id
...


It works fine! Thanks Colin as always!

soichi

--
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@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate