Search code examples
ruby-on-railsrelationshipactiveadminformtastichas-and-belongs-to-many

How to put a self many-to-many relationship together?


Possible Duplicate:
rails many to many self join

I have a problem that I can't find the answer...

The state is: I have a model called Accessories and I also have a relationship has_and_belongs_to_many to a table that connects 2 accessories (self-relationship, columns: accessory_1_id, accessory_2_id). Let's say that the relationship is called by "exceptions".

I'm using Formtastic + ActiveAdmin and I need to get this array of accessories by a relationship because in this way Formtastic can detect the current set of "exceptions" of an existing object (while editing) and set the checkboxes active automaticaly.

I'm sorry for my english.


Solution

  • check this railscasts, it makes a self HABTM association between to users using a friendship association, check it out:

    http://railscasts.com/episodes/163-self-referential-association