# Find with add of an atttributes

**URL:** <https://www.ruby-forum.com/t/find-with-add-of-an-atttributes/155037>\
**Category:** Rails\
**Created:** [December 6, 2008, 7:34pm UTC](https://www.ruby-forum.com/t/find-with-add-of-an-atttributes/155037 "2008-12-06T19:34:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [December 6, 2008, 7:34pm UTC](https://www.ruby-forum.com/t/find-with-add-of-an-atttributes/155037/1 "2008-12-06T19:34:02Z")

</div>

I have wrote this:  
EventDate.find(:all,  
:include =\> [:container,{:event =\>  
[:photo,:event\_type\_names]},{:place=\>:location}],  
:joins =\>" RIGHT JOIN (SELECT  
event\_dates.id,date\_add(event\_dates.date, INTERVAL i DAY ) AS date  
FROM (select 0 as i union all select 0 union all select 1  
union all select 2) as integers CROSS JOIN event\_dates  
WHERE i\<= number\_days AND (event\_dates.days\_of\_week=‘8’  
OR concat(’%’,event\_dates.days\_of\_week,’%’) like  
concat(’%’,DATE\_FORMAT(date\_add( event\_dates.date, INTERVAL i DAY  
),’%w’),’%’))  
ORDER BY date LIMIT 0,40) as date\_days ON date\_days.id=event\_dates.id  
",  
:order=\>“date\_days.date”

I want select also the date\_days.date attribute.  
Is there any mode to do it?  
thanks

---

<div class="post-metadata">

**Author:** ![stratboy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@stratboy](https://www.ruby-forum.com/u/stratboy)\
**Post date:** [December 10, 2008, 4:18am UTC](https://www.ruby-forum.com/t/find-with-add-of-an-atttributes/155037/2 "2008-12-10T04:18:47Z")

</div>

Luca R. wrote:

> concat(‘%’,DATE\_FORMAT(date\_add( event\_dates.date, INTERVAL i DAY  
> ),‘%w’),‘%’))  
> ORDER BY date LIMIT 0,40) as date\_days ON date\_days.id=event\_dates.id  
> ",  
> :order=\>“date\_days.date”
> 
> I want select also the date\_days.date attribute.  
> Is there any mode to do it?

All the date\_days fields will be selected by default,  
the “date” field being available in each result as  
event\_date[:date].

You’re in trouble if this conflicts with an EventDate  
attribute, because Active Records has ignored the  
find :select option when eager loading is used (though  
I’m not sure whether this is still the case for Rails 2.2).  
A patch is available for Rails 2.0.2 that allows :select  
to be used in these circumstances.

Are you sure you want to use a right join? This could  
give Active Record trouble.

–  
Rails Wheels - Find Plugins, List & Sell Plugins -  
[http://railswheels.com](http://railswheels.com)
