0

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.

Community
  • 1
  • 1
Lucas Santos
  • 117
  • 2
  • 11
  • 2
    you have to accept the answers you previously asked. otherwise nobody is willing to answer you. – Siwei Sep 19 '12 at 03:00
  • What answers? I'm sorry but I specified in my first paragraph that I didn't find anything on the web (and I don't asked directly since now). I was using a little hack (if I can say like one) to join two relationships through a method (def exceptions do exception_1 + exception_2 end) but, as I said, Formtastic doesn't accept this "hack". – Lucas Santos Sep 19 '12 at 03:14
  • 1
    Also: This question has been asked and answered before, see here: http://stackoverflow.com/questions/3396831/rails-many-to-many-self-join – David Underwood Sep 19 '12 at 03:27

1 Answers1

0

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

Rodrigo Zurek
  • 4,555
  • 7
  • 33
  • 45
  • Maybe I'm wrong but they the relation are separated, aren't they? I have a table like this: (accessory_1_id | accessory_2_id) { (1, 2); (3; 1) }. I'm sorry for the bad column hehe. I want to grab both rows into an unique relationship. Is that possible (suppose that the foreign value is 1)? – Lucas Santos Sep 19 '12 at 03:43