[Dbix-class] Re: deleting many-to-many relationship entries in one query

Leandro Hermida softdev at leandrohermida.com
Wed Jan 19 15:29:28 GMT 2011

Hi again,

Not sure if this is the way, did:


which works, where 'person2address' relationship in

__PACKAGE__->has_many('person2address' =3D>
'MySchema::Result::Person2Address', 'person_id');
__PACKAGE__->many_to_many('addresses' =3D> 'person2address', 'address');

Is this the only way to do it using relationships?  Seems like this way:



Can't locate object method "person2address" via package


On Wed, Jan 19, 2011 at 4:05 PM, Leandro Hermida <softdev at leandrohermida.com
> wrote:

> Hi everyone,
> Couldn't find the answer to this simple question.... maybe not looking in
> the right place
> I have a standard many-to-many setup:
> person ------< person2address >------- address
> And have defined it in the standard documented way with DBIC.  How do I in
> my code, where I have an instance of the $person object and using
> relationships, delete all this person's person2address entries in one que=
> without touching any addresses?
> Not sure if I am using the right jargon when I said "using relationships"
> like I saw in the manual, what I mean is that I feel this style:
> $person->cars->delete();
> is cleaner and more readable than this:
> $schema->resultset('Car')->search({
>     person =3D> $person,
> })->delete();
> How would I do it with a many-to-many just to delete the relationship
> entries?
> best,
> Leandro
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/dbix-class/attachments/20110119/34f=

More information about the DBIx-Class mailing list