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.
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:
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.
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.