CodeIgniter Forums
Datamapper deleting all associated relationships, many-to-many - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forumdisplay.php?fid=22)
+--- Thread: Datamapper deleting all associated relationships, many-to-many (/showthread.php?tid=56918)



Datamapper deleting all associated relationships, many-to-many - El Forum - 01-30-2013

[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


Datamapper deleting all associated relationships, many-to-many - El Forum - 01-30-2013

[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 );