background preloader

Ruby

Facebook Twitter

Active Record Associations. 1 Why Associations? Why do we need associations between models? Because they make common operations simpler and easier in your code. For example, consider a simple Rails application that includes a model for customers and a model for orders. Each customer can have many orders. Without associations, the model declarations would look like this: Now, suppose we wanted to add a new order for an existing customer. Or consider deleting a customer, and ensuring that all of its orders get deleted as well: With Active Record associations, we can streamline these - and other - operations by declaratively telling Rails that there is a connection between the two models. With this change, creating a new order for a particular customer is easier: Deleting a customer and all of its orders is much easier: To learn more about the different types of associations, read the next section of this guide. 2 The Types of Associations In Rails, an association is a connection between two Active Record models.

Maltize/sublime-text-2-ruby-tests. RubyGems.org | your community gem host. Ruby Programming Language. RVM: Ruby Version Manager - RVM Ruby Version Manager - Documentation.