# Make has\_many conditions truly dynamic

**URL:** <https://www.ruby-forum.com/t/make-has-many-conditions-truly-dynamic/106150>\
**Category:** Rails\
**Created:** [June 6, 2007, 9:50pm UTC](https://www.ruby-forum.com/t/make-has-many-conditions-truly-dynamic/106150 "2007-06-06T21:50:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [June 6, 2007, 9:50pm UTC](https://www.ruby-forum.com/t/make-has-many-conditions-truly-dynamic/106150/1 "2007-06-06T21:50:38Z")

</div>

I have an assocation like this:

has\_many :open\_houses, :conditions =\> {:created\_at\_gt =\> Time.today}

This works thanks to AR::Extensions, but the problem is this is  
initialized when the server starts up. The best solution I have  
thought of is to put make the condition dynamic in SQL such as  
"`created_at` \> NOW()", but that is not trivial since I actually want  
the beginning of the day, not the exact time of request.

How would you do it?

---

<div class="post-metadata">

**Author:** ![dasil003](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9de0a6/32.png) [@dasil003](https://www.ruby-forum.com/u/dasil003)\
**Post date:** [June 6, 2007, 10:44pm UTC](https://www.ruby-forum.com/t/make-has-many-conditions-truly-dynamic/106150/2 "2007-06-06T22:44:48Z")

</div>

dasil003 wrote:

> I have an assocation like this:
> 
> has\_many :open\_houses, :conditions =\> {:created\_at\_gt =\> Time.today}
> 
> This works thanks to AR::Extensions, but the problem is this is  
> initialized when the server starts up. The best solution I have  
> thought of is to put make the condition dynamic in SQL such as  
> "`created_at` \> NOW()", but that is not trivial since I actually want  
> the beginning of the day, not the exact time of request.

Perhaps "`created_at` \> DATE(NOW())"?

> How would you do it?
> 
> >

–  
Jack C.  
removed\_email\_address@domain.invalid
