This project is archived and is in readonly mode.
Bug in rails? Or bug in the model?
Reported by Manoj | August 8th, 2009 @ 07:00 PM
The following are the models in play.
class TestEntity < ActiveRecord::Base
belongs_to :node
end
class Node < ActiveRecord::Base
belongs_to :test_group
belongs_to :build
has_many :test_entities
has_many :networks
has_many :attachments
end
class Build < ActiveRecord::Base
has_many :nodes
end
Referring to build from a test_entity via node fails. Instead of
a build object, an empty node object is returned.
>> te = TestEntity.find(1)
=> #<TestEntity id: 1, node_id: 1, node_type: "MDS", created_at: "2009-08-07 00:18:19", updated_at: "2009-08-07 00:18:19">
>> te.node
=> #<Node id: 1, node_name: "lin3", architecture: "i686", mem_size: 2048, build_id: 1, test_group_id: 1, created_at: "2009-08-07 00:18:19", updated_at: "2009-08-07 00:18:19">
>> te.node.build
=> #<Node id: nil, node_name: nil, architecture: nil, mem_size: nil, build_id: nil, test_group_id: nil, created_at: nil, updated_at: nil>
Querying for the build with the build_id succeeds.
>> build = Build.find(te.node.build_id)
=> #<Build id: 1, lbats_build_id: nil, lbats_build_name: nil, architecture: "i686", os: "GNU/Linux", os_distribution: "redhat", kernel_version: "2.6.18-128.1.1-prep", created_at: "2009-08-07 00:18:19", updated_at: "2009-08-07 00:18:19">
Comments and changes to this ticket
-
Matt Jones August 10th, 2009 @ 08:34 AM
- State changed from new to invalid
Naming models after ActiveRecord methods will cause serious problems, such as this one. 'te.node.build' is calling the build method on te's node association, not doing what you want. The only workaround is, as the old joke goes, to "stop doing that".
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>