Created
May 24, 2009 17:12
-
-
Save jodosha/117189 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
load "test/fixtures.rb" | |
customer = Customer.first | |
# => #<Customer id: 1, name: "Acme Inc.", created_at: "2009-05-24 17:05:45", updated_at: "2009-05-24 17:05:45"> | |
customer.projects | |
# => [#<Project id: 1, name: "Rails", created_at: "2009-05-24 17:05:45", updated_at: "2009-05-24 17:05:45">] | |
customer.projects.destroy_all | |
# => [] | |
Project.all | |
# => [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Contact < ActiveRecord::Base | |
belongs_to :customer | |
belongs_to :project | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Customer < ActiveRecord::Base | |
has_many :contacts | |
has_many :projects, :through => :contacts | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
customer = Customer.create! :name => "Acme Inc." | |
project = Project.create! :name => "Rails" | |
contact = Contact.create! :name => "Bugs Bunny" | |
project.contacts << contact | |
customer.contacts << contact |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Project < ActiveRecord::Base | |
has_many :contacts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment