# Using associations or better avoiding?

**URL:** <https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901>\
**Category:** Rails\
**Created:** [December 21, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901 "2007-12-21T21:42:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 21, 2007, 9:42pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/1 "2007-12-21T21:42:01Z")

</div>

i am wondering if its good to use associations where possible or if its  
better to avoid them …

my concern is: it could lower the performance of my application (because  
new methods are added to the models which are not all necessary for me,  
etc.)

as i am new to ror development i need some expertise advice on this …  
can it lead to problem when using associations everywhere where  
possible?

thanks for your opinion…

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 21, 2007, 9:53pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/2 "2007-12-21T21:53:49Z")

</div>

Associations provide a higher level of abstraction for your app. How  
does  
adding new methods affect performance?

You can optimize slow queries with multiple joins by using sql instead  
of  
ActiveRecord finders. There are also other techniques to speed up the  
app.  
As a beginner I would not worry.

As one of my incompetent manager used to say: “Code like a wind”. LOL.

On Dec 21, 2007 12:42 PM, Michal G. \<  
removed\_email\_address@domain.invalid\> wrote:

> i am wondering if its good to use associations where possible or if its  
> better to avoid them …
> 
> my concern is: it could lower the performance of my application (because  
> new methods are added to the models which are not all necessary for me,  
> etc.)

–  
[http://www.rubyplus.org/](http://www.rubyplus.org/)  
Free Ruby Screencasts

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 21, 2007, 9:58pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/3 "2007-12-21T21:58:38Z")

</div>

thanks for your quick reply … so lets say i have a User model which  
has the following attributes…

firstname  
lastname  
creator\_id  
updater\_id  
reports\_to

so the user was created by a user … and the last modification be done  
by another user … then each user reports to one user … moreover the  
users have friends, send messages, write blog entries, etc.

- would you really add for all this own associations? also e.g. for  
creator and updater - which are e.g. only used on one place?

- i also load the current logged in user on each request … would this  
affect performance if more associations are here?

i am just wondering, because the project is expecting to have 10.000  
uniques a day.

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 21, 2007, 10:22pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/4 "2007-12-21T22:22:30Z")

</div>

> Remember what they say about premature optimization 🙂 ?
> 
> Fred

yeah you are right … but thats why i am asking … if its not that big  
deal then i will use it all the way 🙂 because its a great feature!

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 21, 2007, 10:27pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/5 "2007-12-21T22:27:52Z")

</div>

associations are one of the benefits of using rails. You should be  
happy to be able to use them!

Adam

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 21, 2007, 10:16pm UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/6 "2007-12-21T22:16:40Z")

</div>

On 21 Dec 2007, at 20:58, Michal G. wrote:

> so the user was created by a user … and the last modification be done  
> by another user … then each user reports to one user … moreover the  
> users have friends, send messages, write blog entries, etc.
> 
> - would you really add for all this own associations? also e.g. for  
> creator and updater - which are e.g. only used on one place?

probably

> - i also load the current logged in user on each request … would this  
> affect performance if more associations are here?

Having an association or not isn’t going to affect the loading a  
single record

> i am just wondering, because the project is expecting to have 10.000  
> uniques a day.

Remember what they say about premature optimization 🙂 ?

Fred

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 22, 2007, 11:27am UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/7 "2007-12-22T11:27:47Z")

</div>

thanks… i wasnt so sure about this. now i am using associations  
everywhere 🙂

---

<div class="post-metadata">

**Author:** ![gabru](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/c0e974/32.png) [@gabru](https://www.ruby-forum.com/u/gabru)\
**Post date:** [December 22, 2007, 12:34am UTC](https://www.ruby-forum.com/t/using-associations-or-better-avoiding/123901/8 "2007-12-22T00:34:57Z")

</div>

> it could lower the performance of my application (because  
> new methods are added to the models which are not all necessary for me

Just to be clear, the number of methods in a class has neglible impact  
on performance, so I think your concerns about associations are maybe  
based on a false premise.

///ark
