Tag Archives: multiplicity

Many-to-Many Association

How can you create a many-to-many association in Rails? We discuss two approaches. The first approach uses a join table with a composite primary key, and nothing else; Rails does the heavy lifting. The second approach is through an intermediary class that contains additional data about the relationship of the two elements in the many-to-many association. Continue reading

Posted in Development | Tagged , , | 1 Comment

Sorting Collections of Model Data

In Rails, if you have a multiplicity relationship (such as has_many), how can you sort it? The answer lies in the has_many (and other multiplicity) keywords. You can specify an order attribute, and sort the collection by that field. What’s more, you can even have multiple collections of the same data, sorted differently! Continue reading

Posted in Development | Tagged , | Comments Off

Many-to-Many Recursive Relationship

What’s the best way of creating a many-to-many recursive relationship? The ideal situation is to create a model to represent that relationship. Any data that applies to that relationship, you can place in that model. In this post, we go through an example, end-to-end, to implement such a relationship. Continue reading

Posted in Development | Tagged , , | 1 Comment