Skip to content

Instantly share code, notes, and snippets.

@vessi
Created July 18, 2012 12:33
Show Gist options
  • Save vessi/3135926 to your computer and use it in GitHub Desktop.
Save vessi/3135926 to your computer and use it in GitHub Desktop.
illustration for Law of Demeter for my blog
class Address < ActiveRecord::Base
attr_accessible :country, :city, :street, :building
belongs_to :user
end
class Order < ActiveRecord::Base
belongs_to :user
end
class Order < ActiveRecord::Base
belongs_to :user
delegate :country,
:city,
:street,
:building,
:to => :user,
:prefix => true
end
class User < ActiveRecord::Base
has_one :address
has_many :orders
end
class User < ActiveRecord::Base
has_one :address
has_many :orders
delegate :country,
:city,
:street,
:building,
:to => :address
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment