Add AR::Base#valid! method#8639
Conversation
|
Why would this be preferred over just doing "if valid?...."? |
|
Indeed, @bogdan, can you show a case where |
|
@bogdan I can rewrite the code provided with this: def create_developer_from_linkedin(parameters)
d = Developer.new(parameters)
if d.valid?
d.import_linkedin_profile
d.save!
end
# d # if you still want the invalid record returned
endSo you might want to provide another example where |
|
I need to raise exception instead of returning something. This required me to reverse engineer def create_developer_from_linkedin(parameters)
d = Developer.new(parameters)
if d.valid?
d.import_linkedin_profile
d.save!
else
raise ActiveRecord::RecordInvalid.new(d)
end
end |
|
I think you might want to post the code the make use of the exception raised |
|
@PikachuEXE There are a lot of factors why it's raised including subjective ones like "someone did that long time ago with 0% test coverage". I don't want to explain those details. But I think rails should be flexible enough to give a developer ability to choose between raise exception or return value. |
|
Well since rails 4 are having new Anyway it's up to the core members to decide. |
|
I believe this needs a CHANGELOG entry. Also, could you please document |
|
We are going to review all this API in the next release so we'll not accept this right now. I'll leave this issue open to remember. |
|
Now that the Rails 4 beta is out, has this been reviewed? |
|
Yeah, we will revisit this one form 4.1 |
|
@rafaelfranca This can be reviewed now I guess? |
|
I think I wonder if |
|
This is quite stale now. What is the current blocker to merging this? I also prefer |
Acts same as valid? but raises AR::RecordInvalid exception if validation fails
|
Renamed method to |
Add AR::Base#valid! method
This is helper method in case when some operations should be done on a record before saving. But they doesn't make sence if record is invalid.