Gossamer Forum
Home : Products : Gossamer Links : Development, Plugins and Globals :

Re: [pugdog] Iterating through a table (database) ??

Quote Reply
Re: [pugdog] Iterating through a table (database) ?? In reply to
Hi,

Well, the best is to always only select off what you need (i.e. if you are only recalculating rates, votes, you may just want to do a $table->select(['ID', 'Rating', 'Votes']). Avoid select * unless you need to support custom columns that you don't know what they are.

Quote:
Is it better to do this all in the code, outside of Links->SQL or, should the tables be related, and an event triggered to handle this?


MySQL doesn't support triggers, so code has to handle this. What you can do is use subclass's though. Create your module Plugins::Rate_UserTrack.pm and when creating the tables call $creator->subclass('Plugins::Rate_UserTrack'); Then when you do:

my $table = $DB->table('Rate_UserTrack');

you actually get a Plugins::Rate_UserTrack object. Then in your code, you use inheritance to override modify function:

Code:
sub modify {
my $rec = shift;
my $res = $self->SUPER::modify($rec);
if ($res) {
... code to handle updating vote table upon modification
}
}


Let me know if this makes sense,

Cheers,

Alex
--
Gossamer Threads Inc.
Subject Author Views Date
Thread Iterating through a table (database) ?? pugdog 1996 Feb 22, 2002, 12:31 AM
Post Re: [pugdog] Iterating through a table (database) ??
Alex 1895 Feb 25, 2002, 12:00 PM