# Model extension

**URL:** <https://www.ruby-forum.com/t/model-extension/88795>\
**Category:** Rails\
**Created:** [March 14, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/model-extension/88795 "2007-03-14T13:58:23Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyku](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/34f0e0/32.png) [@kyku](https://www.ruby-forum.com/u/kyku)\
**Post date:** [March 14, 2007, 1:58pm UTC](https://www.ruby-forum.com/t/model-extension/88795/1 "2007-03-14T13:58:23Z")

</div>

Hello all, I’m working on optimising database accesses in my Rails  
application.

I’m having a master model and a logging model. For each master there may  
be many logging objects, so the master has\_many logging objects and the  
logging object belongs\_to master object.

I’d like to quickly fetch the most recently received logging object for  
a master, preferably within a join, so that I can sort and filter in SQL  
rather than in Rails. But I can’t simply use :include =\> logging model  
because there are many of the for a single master.

Is there some possible and elegant solution/workaround of this problem  
in Rails?  
I’m currently replicating the most recently received loging object for  
each machine in a separate table, but since the database is updated by  
other programs I’m afraid of consitency errors.
