This project is archived and is in readonly mode.
default_scope is having a side affecct on create
-
CancelProfileIsBroken
- Tag changed from activerecord, default_scope to activerecord, bugmash, default_scope
-
hsume2 (Henry)
verified on 2-3-stable
I've attached a failing test.
-
Elad Meidar
+1 verified on 2-3-stable, i guess i am lucky for not running into it up until now.
Attached patches for 2-3-stable and master
I generally allowed the scoped attributes to override existing attributes only:
if the attribute value is #blank?
if the attribute is not blank, but the value was initiated via a column default definition.
otherwise the value is not overridden.
-
Elad Meidar
heh, silly Lighthouse textile :)
-
hsume2 (Henry)
I think I get what you've done. However, I think your implementation conficts with #test_default_values_on_empty_strings in base_test.rb. I've attached a patch (with an additional fail test) that fixes it. (Should apply cleanly to master and 2-3-stable)
Also, note: expecting 50000, as opposed to the default value of 70000 defined in the schema.
-
hsume2 (Henry)
Sorry, I don't mean conflict.. exactly. More like, the behavior is different from that in #test_default_values_on_empty_strings.
-
Elad Meidar
- Tag changed from activerecord, bugmash, default_scope to activerecord, bugmash, bugmash-review, default_scope
-
Elad Meidar
Mmmm,
by doing- self.attributes = attributes unless attributes.nil?
self.class.send(:scope, :create).each { |att,value| self.send("#{att}=", value) } if self.class.send(:scoped?, :create)-
self.attributes = attributes unless attributes.nil?</code>
you are overriding the attributes from the scope.... the order of steps i did was to ensure that the last value that the user specified, takes affect.- default db column value
- scoped :conditions
initialize/findparameters
-
-
Elad Meidar
Mmmm,
by doing- self.attributes = attributes unless attributes.nil? self.class.send(:scope, :create).each { |att,value| self.send("#{att}=", value) } if self.class.send(:scoped?, :create) + self.attributes = attributes unless attributes.nil?you are overriding the attributes from the scope.... the order of steps i did was to ensure that the last value that the user specified, takes affect.
- default db column value
- scoped :conditions
initialize/findparameters
- default db column value
-
Elad Meidar
+1 on @hsume2' patch, solves it in a much cleaner way than my patches
-
David Trasbo
+1 though the patch no longer applies to 2-3-stable.
-
Elad Meidar
@david, which one did you try?
-
Josh Sharpe
+1 to hsume2's master patch
Here's the patch for 2-3 which is basically identical to the master patch.
-
sr.iniv.t
+1 verified.
Both patches (hsume2's on master and Josh's on 2-3) apply cleanly and all tests pass.
-
CancelProfileIsBroken
- Tag changed from activerecord, bugmash, bugmash-review, default_scope to activerecord, bugmash-review, default_scope
-
José Valim
- Assigned user set to José Valim
- Milestone cleared.
-
José Valim
- State changed from new to committed
Applied on master. Can someone please rebase the patch for 2-3-stable?
-
Repository
(from [bf9a0ae12b701cba7a8aac2955ce243866ac7bf6]) Fix a bug where default_scope was overriding attributes given on model initialization [#3218 default_scope is having a side affecct on create status:resolved]
Signed-off-by: José Valim jose.valim@gmail.com
http://github.com/rails/rails/commit/bf9a0ae12b701cba7a8aac2955ce24... -
Rizwan Reza
- Tag changed from activerecord, bugmash-review, default_scope to activerecord, default_scope
