Combined with Catalyst's very talkative error trace, I get tons and tons of nonsense, and no useful information. In this case I was told that the problem was that there was an earlier transaction with problems. Well doh! Not very interesting. Tell me why you die, please.
Another thing about DBIC seems to be that $schema is utterly useless after a failed txn_do. You can get a resultset, see the classname, resoultsource etc. But don't you dare! to find some data. Why? Well, I don't know.
But every day since then I've developed fever and pain during daytime, until two days ago I had the first day with no pain killers. My Goodness! What's the point? Depression is an extra added bonus, feeling power- and useless.
Well, now it's over at least, and I can start on the piles that has built themselves in the meantime
Woohoo!!
TPR 3.2 arrived here yesterday, even without having me bother brian about it!
I know it's late compared to everybody else, but hey! Surface mail to Denmark is recognized as the slowest moving item on Earth.
I don't know how many times I've had to request him to send me a new copy because the first was lost in the mail (never any complaints), but now there's hope. The last two issues arrived
The content is not really new, though, as I couldn't help skimming the PDF version. Most important: A lot about Nordic Perl Workshop, this year's most important event!
It's easy to do single-table stuff with DBIx::Class. And even more complex actions are well supported, but you risk duplicating your code if you don't watch out.
Especially if you use Catalyst, it's easy to write the same piece of code to fetch or update related tables in several controllers.
This will surely and quickly become a problem.
Some people will have this in the Model layer of Catalyst. It's OK if all your work is guaranteed to be Catalyst. But what if it's not? What if you want to access your database from e.g. a stand alone server or a cron job?
I use DBIC ResultSets to fill out the hole between simple DBIC classes and the actual code I think that RS suits the bill in a nice way.
This is one way to have more complex database code with DBIx::Class. I'm sure there are a lot of other ways to do it. And I'm sure some people will tell me why I'm wrong
But it's easy to do. Just watch.
In Project::DB::Class:
__PACKAGE__->resultset_class('Project::RS::Class');
Write methods in Project::RS::Class, e.g.
sub create_full {
my ( $self, $args_ref ) = @_;
$self->check_defaults($args_ref);
$self->validate_data($args_ref);
# Get schema
my $schema = $self->result_source->schema;
$schema->txn_do(
sub {
# Do something
}
}
}
and then use it from your controller, script, whatever:
$schema->resultset('Class')->create_full($args_ref);
Somehow it looks scarier in television than IRL. Unless you live within a few hundred meters from Jagtvej 69.