On 12/9/06 5:28 PM, Danial Pearce wrote:
>> depending on your database support, I think the best solution would
>> be to use a DB trigger on insert , that would just populate all of
>> the fields
> 
> As John says somewhere in the documentation. If you are putting
> triggers on your DB, why wouldn't you put them in your object as well?
> Your object is supposed to know pretty much everything about your DB,
> so why would you lie to it and tell it you aren't using any triggers?
> Don't lie, it makes baby jesus cry.

What I wrote in the docs is related to foreign key metadata vs. the
equivalent relationship metadata, specifically that you should use foreign
keys on the perl side only if there are actual foreign keys in the database.
But that's not what we're talking about here.

Unlike foreign key metadata, which is basically just "such and such foreign
key exists," triggers can do pretty much anything.  They cannot be described
so easily.  

I'm a proponent of keeping triggers in one place.  If your database does not
support triggers, then your choice is easy: you implement triggers on the
Perl side.  But if your database supports real triggers, then your have a
choice of where to put the trigger code.  Picking one side or the other is
fine with me, but I balk at trying to maintain the "same" trigger code in
two different languages in two different places.  Maybe for very simple
triggers it's okay, but for anything complex, keeping the two
implementations in sync is a pain.

> if you tell perl there are no triggers, but the DB really does have them, then
> when you save the object you aren't going to see all the work of that trigger
> until you re-load the object.

That's exactly what I do in cases where there are really complex triggers in
the database: re-load() after save()ing.  Yes, it costs one extra query, but
it saves a a lot in maintenance and peace of mind.

-John



-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Rose-db-object mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rose-db-object

Reply via email to