This project is archived and is in readonly mode.

#3088 ✓committed
Luciano G. Panaro

[PATCH] Make has_one with :conditions hash scope build or creation of object with those conditions

Reported by Luciano G. Panaro | August 22nd, 2009 @ 07:24 PM

When building or creating a has_many association, the conditions specified as a hash in the association are merged into the attributes of the new object. As explained in the docs:

Record creations from the association are scoped if a hash is used. has_many :posts, :conditions => {:published => true} will create published posts with @blog.posts.create or

This patch reflects the same behavior for has_one. If accepted, this can also be applied also to belongs_to, or maybe for [build|create]_association in Reflection. The result of this patch is also explained in the doc of has_one:

Record creation from the association is scoped if a hash is used. has_one :account, :conditions => {:enabled => true} will create an enabled account with @company.create_account or @company.build_account.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>

Referenced by