associations - Model a person-to-person relationship in Ruby-on-Rails using has_many :through -


I would like to model the relation of a person with another person, where the relationship is not hierarchical (i.e. friends and colleagues , Instead of parents and children) and I am interested in getting more details about each relationship (for example, the type of relationship, date of establishment). Finally, I want to use the act_as_tree connection to be able to navigate these relationships / diagrams.

Migration:

  Class CreateProfiles & lt; ActiveRecord :: Migration DF self.up create_table: profiling | Table | Table.column: First Name ,: String Table: Last Name ,: String Table. Column: Telephone ,: String Table. Column: Email Address, String Table. Column: Location, String Table. Tamstamp End & Def self.down Drop_table: profile end and class relationships & lt; ActiveRecord :: Migration DF self.up create_table: relationships ,: id = & gt; Make false Table | Table.column my_id: integer table. Column your_id: integer table. column Relationship type: string table. column dateEstablished: date table.column Notes: text table. Tiemestamps end end def self.down drop_table: Relationship end end  

Model:

  class person & lt; ActiveRecord :: Base is has_many: relationships,: foreign_key = & gt; "My_id" has_many: persons: through = & gt; : End relationships of relationships & lt;  
  1. How do I properly define relationships between these tables?
  2. As my_id / your_id combination is unique, does it mean to eliminate the id on the relationships table?
  3. Is there a better name for 'my_id'? 'Your_id' field to use ROR conferences?
  4. If there is no one named 'parent_id' in the column then will I have difficulties with the act_as_tree relationship?

    1. Just a few days ago, a similar question was asked Was:. I tried to document on a large scale how looped unions have to do there. Maybe it will help you?

    2. In the train id without tables can be seen only with the is_and_bolongs_to_may association. Regular is_may: Through the association with the associations, the table model is like any other activivircord model, and an id column is required

    3. < P> I do not know there is a good conference here, but those examples are a bit weird, you can use them as a relationship.your , which makes me feel a bit awkward individually. Perhaps your_person_id , which will be accessed as relationship.your_person , and make it clear that you are working with a person example Are you Another option might be relationship.you .
    4. I have never used the acts, but you can add it equally to the parameter: Actions_as_tree: foreign_key = & gt; As I have said in my reply, it seems that your biggest difficulty is bilateral relations, A person A is from a person B If it is added, it does not mean that the person is associated with B person. In ActiveRecord, which I can tell, it is difficult to accomplish unfortunately.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -