Tuesday, March 23, 2010

[Rails] Fixtures and Associations

I have a concrete table with an associated join table and I'm trying to
load up some test data but cannot seem to get the fixtures file correct.
The parent/child relationship works great but the fixtures fail to load.
Any help would be greatly appreciated.

Here is what I have...

# app/models/node.rb
class Node < ActiveRecord::Base
belongs_to :category
belongs_to :status

has_one :parents,
:class_name => "NodeGroup",
:foreign_key => "child_id"

has_one :parent, :through => :parents

has_many :children,
:class_name => "NodeGroup",
:foreign_key => "parent_id"

end

# app/models/node_group.rb
class NodeGroup < ActiveRecord::Base
belongs_to :parent, :class_name => "Node"
belongs_to :child, :class_name => "Node"
end

# test/fixtures/nodes.yml
parent1:
name: Parent1
children: child1

parent2:
name: Parent2

child1:
name: Child1
--
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 this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate