Reputation: 18318
In my rails application I have a table with the following columns (table name categories)
How do I setup the relationship so I can do something like @category.parent.title?
Upvotes: 1
Views: 630
Reputation:
belongs_to :category, :foreign_key => :parent_id
has_many :categories, :foreign_key => :parent_id
Note that if a category has no parent category and you try to access it anyway, you get an error.
Upvotes: 5