Re: [Rails] Self Reference, Almost There (I Hope!)
On 20 June 2010 19:12, Michael Satterwhite <lists@ruby-forum.com> 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.
There might be some other issues... but get to them after the
Relationship models are working (try creating one in the console to
make sure it works...)
--
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