[Solar-talk] Making $record->save() return boolean?
Kilbride, James P.
James.Kilbride at gd-ais.com
Wed Mar 12 07:11:14 CDT 2008
I personally prefer the boolean rather than a try catch. Try/Catch
always seems a bit more complex and I think the boolean is kind of nice.
Easy to do the capture and pull for more information if I want it or I
simply log that there was an error at that point. Very simple and easy
to read as well.
James Kilbride
-----Original Message-----
From: solar-talk-bounces at lists.solarphp.com
[mailto:solar-talk-bounces at lists.solarphp.com] On Behalf Of Paul M Jones
Sent: Tuesday, March 11, 2008 10:05 PM
To: solar-talk at lists.solarphp.com
Subject: Re: [Solar-talk] Making $record->save() return boolean?
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
_______________________________________________
Solar-talk mailing list
Solar-talk at lists.solarphp.com
http://mailman-mail3.webfaction.com/listinfo/solar-talk
More information about the Solar-talk
mailing list