This project is archived and is in readonly mode.
[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 @blog.posts.build.
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
-
CancelProfileIsBroken September 25th, 2009 @ 12:47 PM
- Tag changed from 2-3-stable, :conditions, has_one to 2-3-stable, :conditions, bugmash, has_one
-
John Pignata September 26th, 2009 @ 03:11 AM
+1 on the feature - this makes a lot of sense to also be a part of has_one associations.
-1 on the patch as I couldn't get it to cleanly apply to 2-3-stable. As this is a new feature and not a maintenance fix it should be written as a patch to master though anyway.
-
Anuj Dutta September 26th, 2009 @ 01:17 PM
- Tag changed from 2-3-stable, :conditions, bugmash, has_one to 2-3-stable, :conditions, bugmash, bugmash-patch, has_one
+1 on the feature - makes sense
-
Anuj Dutta September 26th, 2009 @ 01:18 PM
- Tag changed from 2-3-stable, :conditions, bugmash, bugmash-patch, has_one to 2-3-stable, :conditions, bugmash-patch, has_one
-
Anuj Dutta September 26th, 2009 @ 01:20 PM
- Tag changed from 2-3-stable, :conditions, bugmash-patch, has_one to 2-3-stable, :conditions, bugmash, bugmash-patch, has_one
-
Luciano G. Panaro September 26th, 2009 @ 02:11 PM
Taking a look at the patch - will fix it right away
-
Luciano G. Panaro September 26th, 2009 @ 03:31 PM
Updated patch for 2-3-stable and created patch for master.
-
Elomar França September 26th, 2009 @ 07:32 PM
+1 for this feature.
Both patches from luciano.panaro applied successfully.
-
Anuj Dutta September 27th, 2009 @ 12:01 AM
Patch applies successfully on 2-3-stable. Green on tests.
-
sr.iniv.t September 27th, 2009 @ 04:37 AM
+1 verified.
The patches apply cleanly and all tests pass. I've always wanted this feature on AR.
-
CancelProfileIsBroken September 27th, 2009 @ 11:55 AM
- Tag changed from 2-3-stable, :conditions, bugmash, bugmash-patch, has_one to 2-3-stable, :conditions, bugmash, bugmash-review, has_one
-
CancelProfileIsBroken September 27th, 2009 @ 12:34 PM
- Tag changed from 2-3-stable, :conditions, bugmash, bugmash-review, has_one to 2-3-stable, :conditions, bugmash-review, has_one
-
Repository September 28th, 2009 @ 03:29 AM
- State changed from new to committed
(from [14a6794a8ef9995c45a86e95c45d315c61087103]) Make has_one with :conditions hash scope build or creation of the associated object with those conditions
Signed-off-by: Michael Koziarski michael@koziarski.com
[#3088 state:committed] http://github.com/rails/rails/commit/14a6794a8ef9995c45a86e95c45d31... -
Repository September 28th, 2009 @ 03:29 AM
(from [4168f876238982d0d584006f50188071928a8b7f]) Make has_one with :conditions hash scope build or creation of the associated object with those conditions
Signed-off-by: Michael Koziarski michael@koziarski.com
[#3088 state:committed] http://github.com/rails/rails/commit/4168f876238982d0d584006f501880... -
Rizwan Reza May 15th, 2010 @ 06:42 PM
- Tag changed from 2-3-stable, :conditions, bugmash-review, has_one to 2-3-stable, :conditions, has_one
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="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3088 [PATCH] Make has_one with :conditions hash scope build or creation of object with those conditions Signed-off-by: Michael Koziarski michael@koziarski.com [#...
- 3088 [PATCH] Make has_one with :conditions hash scope build or creation of object with those conditions Signed-off-by: Michael Koziarski michael@koziarski.com [#...