# Model concept

**URL:** <https://www.ruby-forum.com/t/model-concept/136019>\
**Category:** Rails\
**Created:** [April 28, 2008, 7:21am UTC](https://www.ruby-forum.com/t/model-concept/136019 "2008-04-28T07:21:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [April 28, 2008, 7:21am UTC](https://www.ruby-forum.com/t/model-concept/136019/1 "2008-04-28T07:21:49Z")

</div>

hi,actually i am doing a one web related project, i want know that in  
project fetching data using model ya using query which is efficient? and  
how  
i am always confuse about model so hoe use model in application  
efficiently .

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [April 28, 2008, 7:34am UTC](https://www.ruby-forum.com/t/model-concept/136019/2 "2008-04-28T07:34:51Z")

</div>

Sunny B. wrote:

> hi,actually i am doing a one web related project, i want know that in  
> project fetching data using model ya using query which is efficient? and  
> how  
> i am always confuse about model so hoe use model in application  
> efficiently .

It’s rough, but I think you’re asking how to use a Rails’ model  
efficiently. Is that correct?

Do you have an example of a model you’ve created we can look at?

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [April 28, 2008, 7:53am UTC](https://www.ruby-forum.com/t/model-concept/136019/3 "2008-04-28T07:53:43Z")

</div>

Daniel W. wrote:

> Sunny B. wrote:
> 
> > hi,actually i am doing a one web related project, i want know that in  
> > project fetching data using model ya using query which is efficient? and  
> > how  
> > i am always confuse about model so hoe use model in application  
> > efficiently .
> 
> It’s rough, but I think you’re asking how to use a Rails’ model  
> efficiently. Is that correct?
> 
> Do you have an example of a model you’ve created we can look at?

ya , its correct for example i am fetching photo object using model like  
@album.album\_photos.photos so internally it query on three table but i  
can directly fetch photos on query on photo table? so which is  
efficient?  
if data cm from model it cached or not? explain brief.

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [April 28, 2008, 8:32am UTC](https://www.ruby-forum.com/t/model-concept/136019/4 "2008-04-28T08:32:09Z")

</div>

Maybe you can use rails relational mapping.

example :  
…

class Album \< ActiveRecord  
has\_many :album\_photos, :dependent =\> true  
has\_many :photos, :through =\> :album\_photos

…

class Photo \< ActiveRecord  
has\_many :album\_photos, :dependent =\> true  
has\_many :albums, :through =\> :album\_photos

…

class AlbumPhoto \< ActiveRecord  
belongs\_to :album  
belongs\_to :photo

…

I hope this Trough Association matter can help your problem.

Sincerely,  
Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [April 28, 2008, 8:36am UTC](https://www.ruby-forum.com/t/model-concept/136019/5 "2008-04-28T08:36:45Z")

</div>

## IMPLEMENTATION :

“BEFORE”

> @album.album\_photos.photos

“AFTER”  
@album.photos

Sincerely,  
Reinhart  
[http://teapoci.blogspot.com](http://teapoci.blogspot.com)
