This project is archived and is in readonly mode.
has_one through incorrect id add
Reported by ronin-131274 (at lighthouseapp) | January 5th, 2011 @ 05:15 AM
class Device < ActiveRecord::Base
has_many :units has_many :components, :through => :units end
class Component < ActiveRecord::Base
has_one :unit has_one :device, :through => :unit end
class Unit < ActiveRecord::Base
belongs_to :device belongs_to :component end
Everything I add a device_id to a component, it adds 1 to the device_id stored in the Units table.
x=Component.new
x.device=1
x.save
device_id=2 in the Unit model
Comments and changes to this ticket
-
gerardc January 11th, 2011 @ 02:10 PM
Why would you add 1 as the device for x and not a Component object?
-
gerardc January 11th, 2011 @ 02:15 PM
Edit to my previous comment:
Why would you set x.device to hold the value 1 instead of a Device object
/newb
-
ronin-131274 (at lighthouseapp) January 11th, 2011 @ 02:23 PM
If I wanted to assign a component to a device.
-
Dan Pickett March 12th, 2011 @ 04:19 PM
this looks as though it doesn't honor the contract in associations.
x.device = 1 is not a proper assignment. You must assign x's device association to a device object.
x.device_id = 1 should successfully assign the foreign key for you.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>