# ActiveRecord::Associations ER diagram/macros

**URL:** <https://www.ruby-forum.com/t/activerecord-associations-er-diagram-macros/60773>\
**Category:** Rails\
**Created:** [May 17, 2006, 12:06pm UTC](https://www.ruby-forum.com/t/activerecord-associations-er-diagram-macros/60773 "2006-05-17T12:06:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![goa103](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@goa103](https://www.ruby-forum.com/u/goa103)\
**Post date:** [May 17, 2006, 12:06pm UTC](https://www.ruby-forum.com/t/activerecord-associations-er-diagram-macros/60773/1 "2006-05-17T12:06:15Z")

</div>

Hello,

I found an interesting ER diagram on the “Module:  
ActiveRecord::Associations::ClassMethods” page of the Rails Framework  
Documentation :  
[http://ar.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html](http://ar.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)

At the beginning we can read Â« Associations are a set of macro-like  
class  
methods for tying objects together through foreign keys. They express  
relationships like “Project has one Project Manager” or “Project belongs  
to  
a Portfolio”. Â». I would like to learn more about that concept of  
expressing  
relationships between objects. I only knew it as a design concept and  
can’t  
remember seeing it applied “as this” in the source code using macros. I  
find  
the idea interesting. Is it some kind of Ruby “Best Practices” or  
design/development pattern ?

JM.

PS : Note that the diagram is not displayed on the “official” page :

> **[ActiveRecord::Associations::ClassMethods](https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html)**
>
> Associations are a set of macro-like class methods for tying objects together through foreign keys.

I was only able to find it on that “mirror”.

---

<div class="post-metadata">

**Author:** ![goa103](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@goa103](https://www.ruby-forum.com/u/goa103)\
**Post date:** [May 17, 2006, 12:09pm UTC](https://www.ruby-forum.com/t/activerecord-associations-er-diagram-macros/60773/2 "2006-05-17T12:09:05Z")

</div>

Sorry for posting a “truncated” message but it was originally posted on  
Usenet and I forgot to rewrite it.

---

<div class="post-metadata">

**Author:** ![goa103](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/e495f1/32.png) [@goa103](https://www.ruby-forum.com/u/goa103)\
**Post date:** [June 9, 2006, 9:01am UTC](https://www.ruby-forum.com/t/activerecord-associations-er-diagram-macros/60773/3 "2006-06-09T09:01:34Z")

</div>

Jean-Marc Molina wrote:

> At the beginning we can read Â« Associations are a set of macro-like  
> class methods for tying objects together through foreign keys. They  
> express relationships like “Project has one Project Manager” or  
> “Project belongs to a Portfolio”. Â».

Reading the “Simplify Business Logic with PHP DataObjects” [ONLamp.com](http://ONLamp.com)  
article by Darryl Patterson I found an interesting comment about the  
Class::DBI [2] Perl module : Â« The greatest part about it is that you  
can declare relationships between classes/tables by indicating that a  
certain column in your table either is a foreign key (has\_a) or that  
your table’s primary key is referenced from another one (has\_many). All  
the joins will then happen behind the scenes and you can use simple  
accessors to navigate your relations. Â». The same terms as in the  
diagram are used : “has\_one”, “has\_many”… I know these are common  
software design terms but I’m pretty sure it’s not a coÃ¯ncidence. I’m  
about to investigate on Perl communities, stay tuned…

JM.

Notes :

- [1] [http://www.onlamp.com/pub/a/php/2004/08/05/dataobjects.html](http://www.onlamp.com/pub/a/php/2004/08/05/dataobjects.html)
- [2] [http://www.class-dbi.com](http://www.class-dbi.com)
