On 20/06/2010 20:18, Michael Pavling wrote:
On 20 June 2010 19:12, Michael Satterwhite<[email protected]> wrote:
class CreateRelationships< ActiveRecord::Migration
def self.up
create_table :relationships, :id => false do |t|
t.integer :category_id
t.integer :parent_id
t.integer :sort_order
t.timestamps
end
end
end
If "relationships" is a join table, then it can't have any fields
other than the two foreign keys.
class Relationship< ActiveRecord::Base
belongs_to :category, :class_name => 'Category',
:foreign_key => 'category_id'
belongs_to :parent, :class_name => 'Category',
:foreign_key => 'parent_id
end
Right - so Relationship is an AR model - it *needs* an ID column.
<snip>
Also, you need to refer to the relationships association in the Category
class as follows:
has_many :parents, :class_name => 'Category', :through =>
:relationships, :source => :parent
(In case there's anybody still interested :) )
--
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 [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.