Welcome Guest, Not a member yet? Register   Sign In
Datamapper deleting all associated relationships, many-to-many
#1

[eluser]msteudel[/eluser]
I have a three table many-to-many relationship:

Code:
sites
id | site_name

locations
id | location_name

locations_sites
site_id | location_id

I'm trying to delete all the locations associated with a specific site. I tried to do it like so:

Code:
$site = new Site();
        $site->where( 'id', $site_id )->get();

        $location = new Location();
        $locations = $location->where( 'site_id', $site_id )->get();

        foreach( $locations as $l ) {
            echo $l->location_name . ' ';
        }
        $site->delete( $locations );

But it's not deleting the associated locations. I feel like I'm close ...

TIA
#2

[eluser]msteudel[/eluser]
So I think this stuff was working, and I was looking at the wrong place to confirm deletion. Anyway this was my final code:

Code:
$site = new Site();
$site->where( 'id', $site_id )->get();

$site->location->get();

$site->delete( $site->location->all );





Theme © iAndrew 2016 - Forum software by © MyBB