title: Is it appropriate to repeat data in models to satisfy using law of demeter in collections?
body: <p>This is a contrived example, say I want to list the population of a country that a person has a friend in, here are two setups below.  Would it be best to repeat data in the models?</p>
  
  <p>I've been told that the <a href="http://en.wikipedia.org/wiki/Law_of_Demeter" rel="nofollow">Law of Demeter</a> is important to follow, the example is you tell a dog to walk, it is folly to command his legs to walk.  </p>
  
  <p>In my wealth of inexperience (noob) I have found that the query would be much easier to do when the models repeat data, <code>People.where(:country =&gt; friend.country)</code>, vs collections where there are chained associations (which have been impossible thus far): <code>People.where(:city =&gt; { :county =&gt; { :region =&gt; { :country =&gt; friend.city.county.region.country }}})</code>  (It would really help this noob here understand the concept if you could imagine the correct contrived LoD setup and syntax, I really hope I didn't use an example that has nothing to do with the Law of Demeter)  I've tried applying LoD via <code>delegate</code> and was told I'm still chaining (which I am), the only solution I can think of is to repeat data that could be accessible via associations.</p>
  
  <p>But I hate repeating data!  This is due to following DHH's Rails tutuorial where we re-create twitter, he showed how great it is to create relationships vs repeating data.</p>
  
  <p>Should repeating data be appropriate to get the associations less chained?  </p>
  
  <p>Models, repeating data</p>
  
  <pre><code>class Country &lt; ActiveRecord::Base    
    has_many :regions    
    has_many :counties    
    has_many :cities    
    has_many :people
  end
  
  class Region &lt; ActiveRecord::Base
    has_one :country
    has_many :counties
    has_many :cities    
    has_many :people
  end
  
  class County &lt; ActiveRecord::Base
    has_one :country
    has_one :region
    has_many :cities    
    has_many :people
  end
  
  class City &lt; ActiveRecord::Base
    has_one :country
    has_one :region
    has_one :county    
    has_many :people
  end
  
  class Person &lt; ActiveRecord::Base
    has_one :country
    has_one :region
    has_one :county    
    has_one :city
    has_many :relationships
    has_many :friends, :through =&gt; :relationships
  end
  </code></pre>
  
  <p>vs models with chained associations</p>
  
  <pre><code>class Country &lt; ActiveRecord::Base    
    has_many :regions   
  end
  
  class Region &lt; ActiveRecord::Base
    belongs_to :country
    has_many :counties
  end
  
  class County &lt; ActiveRecord::Base
    belongs_to :region
    has_many :cities
  end
  
  class City &lt; ActiveRecord::Base
    belongs_to :county
  end
  
  class Person &lt; ActiveRecord::Base
    belongs_to :city
  end
  </code></pre>