Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Bug in rails? Or bug in the model?

#3009

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">

Reported by Manoj · August 8th, 2009 @ 07:00 PM

State: invalid
Milestone: none
Assigned to: nobody
Importance: none

Activity

  1. Matt Jones
    Matt Jones
    • 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".

    August 10th, 2009 @ 08:34 AM