[Solar-talk] Making $record->save() return boolean?
Paul M Jones
pmjones at paul-m-jones.com
Tue Mar 11 21:04:44 CDT 2008
On Mar 11, 2008, at 12:53 , Travis Swicegood wrote:
> Howdy...
>
> On Mar 11, 2008, at 8:56 AM, Paul M Jones wrote:
>
>> For record saving, which is a frequent occurrence, I think this is
>> a valuable convenience.
>>
>> Anybody have strong feelings about this one way or the other?
>
> I'm not sure I see a use case for having it return a boolean? The
> name save() to me implies it worked or there's a problem. I don't
> see a case where returning false is necessary.
The idea is to replace a commonly-needed but verbose idiom (try
save(), catch "Solar_Sql_Model_Record_Exception_Invalid" exception,
process exception if needed) with a less-verbose one (save() returns
true or false, with additional info available on request).
> If a particular save method is supposed to do something on a
> failure, shouldn't that save method extend the superclass' method
> and implemented that logic inside the model so it is portable and
> reusable?
The save() method *can* be extended to perform other behaviors; this
does not prevent that. However, the most-common case is to set the
"invalid" messages on the respective columns in the record, and tell
the caller that the save failed for some reason. That is what's
handled by this.
Additionally, what is needed in response may change from controller to
controller; all behavior for all controllers cannot always be
encapsulated in the model.
-- pmj
More information about the Solar-talk
mailing list