On 25 March 2011 20:24, R. K. <li...@ruby-forum.com> wrote:
> I have an Ingredient which has a Measurement.
>
> class Ingredient < ActiveRecord::Base
>  has_one :measurement
>  belongs_to :recipe
>
>  accepts_nested_attributes_for :measurement
> end
>
> class Measurement < ActiveRecord::Base
>  belongs_to :ingredient
> end
>
>
> The schemas appear right:
>
>  create_table "ingredients", :force => true do |t|
>    t.integer  "measurement_id"
>    t.integer  "recipe_id"
>    t.string   "quantity"
>    t.string   "food"
>    t.datetime "created_at"
>    t.datetime "updated_at"
>  end
>
>
>  create_table "measurements", :force => true do |t|
>    t.string   "size"
>    t.float    "quantity"
>    t.string   "abbreviation"
>    t.string   "measurement"
>    t.string   "measurement_type"
>    t.string   "equivalent"
>    t.datetime "created_at"
>    t.datetime "updated_at"
>  end

It is the belongs_to object that should have the foreign key, so
measurement should have an ingredient_id, not vice versa.  Or the
relationship should be the other way round.

Colin

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to