<cfset user = ormService.createRecord("user")>
<cfset user.load(UserId=1)>

<cfif m.isDirty()>
    failed, user does not exist
<cfelse>
    success
</cfif>

After a successful load the record will be cleaned, ie the current To will
be copied to the InitialTo, so isDirty will return false, this only happens
if load matches a record in the db.  The only gotcha with this is the
default value for UserID is normally 0 (zero) so user.load(UserId=0) will
cause isDirty() to return false, but you just have to check for that case
wherever you create your records.

Alternatively user.exists() will tell you whether a user with that id exists
in the db, but will cost you another query.

Chris


On 2/13/08, Simon Stanlake <[EMAIL PROTECTED]> wrote:
>
> When I call load() on a record and no match is found in the database
> there is no exception thrown or (as far as I can tell) method to
> determine if the record I now have is actually a record in the database.
>
> For example if I do...
>
> <cfset user = ormService.createRecord("user")/>
> <cfset user.setUserid(1)/>
> <cfset user.load()/>
>
> ... and there's no user record with userid=1, I'm left with a user
> object that has a userid of 1 and "" for the rest of it's properties.
> How do I determine the difference between this and a real user record
> with userid=1?
>
> I can see that the DAO uses the Gateway to get a query, and will throw a
> NoMatchingRecord exception if the resultset has 0 records. However this
> exception is caught in the abstractRecord.load() method. Maybe there is
> an architectural detail I'm missing as to why you would want to hide a
> NoMatchingRecord exception from the caller.
>
> Thanks - Simon
>
>
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> -- --
> Reactor for ColdFusion Mailing List
> [EMAIL PROTECTED]
> Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
> -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
> -- --
>
>
>


-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
[EMAIL PROTECTED]
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Reply via email to