Wouldn't throwing it in a try catch block be better than what your doing
here?

And I would refactor this

if(isNUll(EntityLoadByExample(x)))
 x.save()
else
 x = EntityLoadByExample(x)

as

x = EntityLoadByExample(x)
if(isNUll(x))
 x.save()
But I think for better understanding to what the code is doing placing it in
a try catch block, and checking for the exception of a constraint error
would be better and easier to read and understand in 6-12 months time.

On Thu, Dec 17, 2009 at 6:06 AM, Charlie Stell <charlie.st...@gmail.com>wrote:

>
> I was using EntityLoadByExample today and the behavior wasn't what I was
> expecting.
>
> I expected it would be able to replace the query I always do right before
> insert (the "check" query) - to make sure that the insert wont conflict
> with
> unique constraints.
>
> Ive bee using it like this:
>
> x = entityNew("a")
>
> x.setP1("...")
> x.setP2("...")
> [...n]
>
> if(isNUll(EntityLoadByExample(x)))
>  x.save()
> else
>  x = EntityLoadByExample(x)
>
> This works great whenever all the properties for "a" are simple
> (fieldtype=column).
>
> But when I tried this with an object that has a many-to-one defined, it
> ignores this difference.
>
> I've dumped x and EntityLoadByExample(x) right next to each other and see
> that the "parent" object in the two dumps are different (different data, to
> include pks).
>
> Right now Im using
>
> arrayLen(EntityLoad("a",{p1='#p1#',p2='#p2#',p3='#parent#'})) eq 0 in place
> of isNUll(EntityLoadByExample(x)).
>
> This seems to do the trick. But does anyone know if I know
> if EntityLoadByExample should be able to handle this?
>
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329200
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: 
http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=11502.10531.4

Reply via email to