[Dbix-class] Deleting with JOIN's
Yves Räber
yraber at mailup.net
Fri Oct 17 16:17:49 BST 2008
Hello,
I'm having problem trying to delete with JOINs.
Here is an extract of my schema :
DBIC::MyApp::Batch->belongs_to('script' =>
'DBIC::MyApp::Script' ,'idscript');
DBIC::MyApp::Script->has_many('batch' =>
'DBIC::MyApp::Batch','idscript');
DBIC::MyApp::Script->has_many('astextensions' =>
'DBIC::MyApp::Astextensions', { 'foreign.exten' => 'self.idscript' });
DBIC::MyApp::Astextensions->belongs_to('script' =>
'DBIC::MyApp::Script','exten');
And That's the piece of code that I'm trying to make work :
my $extensions = $c->model('MyApp::Batch')->search(
{
state => ['STOPPED', 'ARCHIVED', 'DONE']
}
)->search_related('script')->search_related('astextensions');
Now if I try $extensions->delete , this is what I get (I have to admit I
don't really understand why I get this):
DELETE FROM ast_extensions WHERE ( ( ( state = ? ) OR ( state = ? ) OR
( state = ? ) ) ): 'STOPPED', 'ARCHIVED', 'DONE'
But if I try something else, like $extensions->count(), the query is
just fine :
SELECT ... FROM Batch me JOIN Script script ON ( script.idscript =
me.idscript ) LEFT JOIN ast_extensions astextensions ON
( astextensions.exten = script.idscript ) WHERE ( ( ( state = ? ) OR
( state = ? ) OR ( state = ? ) ) ): 'STOPPED', 'ARCHIVED', 'DONE'
Am I completely wrong ? Any clues ?
Thanks.
Yves.
More information about the DBIx-Class
mailing list