protected function saveLocationsToListing($model) { foreach ($_POST['Listing']['p_locations'] as $locationId) { $listingLocation = new ListingLocation(); $listingLocation->listing_id = $model->listing_id; $listingLocation->location_id = $locationId; if (!$listingLocation->save()) { return false; } } return true; }