This project is archived and is in readonly mode.
[ActiveRecord] create(:association_id => @object.id) vs create(:association_id => @object)
-
Radosław Bułat
No comments? It could save a lot of time for me and I believe that others to.
-
Radosław Bułat
- Assigned user set to josh
-
josh
- Assigned user changed from josh to Pratik
-
CancelProfileIsBroken
- Tag changed from activerecord, create to activerecord, bugmash, create
- Assigned user cleared.
-
Elad Meidar
+1 verified on 2-3-stable and master.
iv'e attached a patch with a failing test (created on 2-3-stable, applies on master too).
-
sr.iniv.t
+1 verified.
Elad's patch applies cleanly on master and 2-3-stable and the issue is reproducible.
-
Elad Meidar
i Dug into it, and came up with
type_castas the issue, i added a special case for type casting AR:Base decedent instances as values (defaults to primary key returns as value).The only issue is in the test, which still fails.
I scattered a bunch of debug prints all over the method chaincreate=>attributes_with_quotes' =>read_attribute=>type_castto make sure that the right value is assigned and still, when i access@post.attributesin the test,author_idis as expected but@post.author_idis still 1. (more on this "gist":http://gist.github.com/194887 )iv'e attached a patch with the changes and the failing test, + some debug prints to make it clear.
-
Elad Meidar
argh, markdown fails. :)
-
Matías Flores
I've verified the issue exists and it's easily reproducible
-
Elomar França
+1, verified.
I had some failures when applying the patch from Elad Meidar, both on master and 2-3-stable.
I think this issue could also be solved in "write_attribute". If the attr is from a belongs_to association and the given value is a AR::Base, write value.id to the attribute, but I couldn't discover how implement it yet :(
-
Evgeniy Dolzhenko
+1 just spend an hour or so on figuring out the exact issue, and then found this ticket.
The following snippet from
Column#type_castseems just wrong (or just the intention isn't obvious):when :integer then value.to_i rescue value ? 1 : 0 -
Evgeniy Dolzhenko
@Elad, the problem is that your patch adds new functionality to
Column#type_castbut doesn't repeats that forColumn#type_cast_codewhich is user by the attribute read method (@post.author_idin your case) -
Ryan Bigg
Automatic cleanup of spam.
-
Jeff Kreeftmeijer
Automatic cleanup of spam.
