>
> First I used your example posted, so your eample has that IsNULL error to
> begin with.
>
My example:

if(isNUll(EntityLoadByExample(x)))
 x.save() //If it's not found, save it - this will cause an insert without
problem
else
 x = EntityLoadByExample(x) //if it was found, use it

I think I see what you were meaning though -

I could use:
y = EntityLoadByExample(x,true)
if(isNull(y))
 x.save()// you don't want x to be null here.
else
 x = y
-This would avoid asking the system the same thing twice... a little better
on processing.



> Secondly, I am not sure why you need to retrieve the record again? When you
> create an Entity, and then populate it and after saving there is no need to
> retrieve it again as everything that is in the DB is populated in the
> Entity.
>
> This is to retrieve the record in subsequent requests where you have
neither the PK or the entity already identified.


> If you are needing something more, then I suggest looking into optimistic
> locking. ColdFusion 9 ORM allows a developer to define 2 more fields for
> this exact behaviour. One is called version, and the other is timestamp.
> You
> can either use one of the other, or both depending on how tight you want to
> make this.
>
> But at the end of the day reloading an Entity that has been saved is only
> actually just wasting a DB call, as it will always be the same in this
> situation you describe regardless.
>


> There maybe more to what you are doing, but from what you have mentioned
> your work flow process is overkill.
>

Here's an example - say I wan't to store email addresses as they come into
my mailbox - I have the properties set up like (and this is very
rough pseudo code):

component email
property - id fieldtype: id
property - user - fieldtype: column
property - domain - fieldtype:many-to-one cfc: domain
unique constraint on user and fkcolumn

component domain
property - fieldtype: id
property - name fieldtype:column
unique constraint on name

An email comes in, a scheduled task picks it up, and separates the
email-address into curUser and curDomain (both of which are just string)

This is the pattern I've been using:
----
domain = entityNew("domain");
domain.setName(curDomain)
check = entityLoadByExample(domain,true)
if(isNUll(check))
 domain.save()
else
 domain = check

email = entityNew("email")
email.setDomain(domain);
email.setUser(curUser);
check = entityLoadByExample(email,true)
if(isNUll(check))
 email.save()
else
 email = check
----

I know I could override the setDomain method for email here - but wouldn't
it essentially be have the domain-retrieve-or-create code in it?

Or am I missing something all together?

Thanks for the feedback!


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
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:329203
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to