@@ -273,32 +273,36 @@ public function createMany(array $records)
273273 /**
274274 * Destroy the embedded models for the given IDs.
275275 *
276- * @param array|int $ids
276+ * @param mixed $ids
277277 * @return int
278278 */
279279 public function destroy ($ ids = array ())
280280 {
281- // We'll initialize a count here so we will return the total number of deletes
282- // for the operation. The developers can then check this number as a boolean
283- // type value or get this total count of records deleted for logging, etc.
284- $ count = 0 ;
285-
286- if ($ ids instanceof Model) $ ids = (array ) $ ids ->getKey ();
287-
288- // If associated IDs were passed to the method we will only delete those
289- // associations, otherwise all of the association ties will be broken.
290- // We'll return the numbers of affected rows when we do the deletes.
291- $ ids = (array ) $ ids ;
281+ $ ids = $ this ->getIdsArrayFrom ($ ids );
292282
293283 $ primaryKey = $ this ->related ->getKeyName ();
294284
295285 // Pull the documents from the database.
296286 foreach ($ ids as $ id )
297287 {
298288 $ this ->query ->pull ($ this ->localKey , array ($ primaryKey => $ this ->getForeignKeyValue ($ id )));
299- $ count ++;
300289 }
301290
291+ return $ this ->dissociate ($ ids );
292+ }
293+
294+ /**
295+ * Dissociate the embedded models for the given IDs without persistence.
296+ *
297+ * @param mixed $ids
298+ * @return int
299+ */
300+ public function dissociate ($ ids = array ())
301+ {
302+ $ ids = $ this ->getIdsArrayFrom ($ ids );
303+
304+ $ primaryKey = $ this ->related ->getKeyName ();
305+
302306 // Get existing embedded documents.
303307 $ documents = $ this ->getEmbeddedRecords ();
304308
@@ -313,7 +317,28 @@ public function destroy($ids = array())
313317
314318 $ this ->setEmbeddedRecords ($ documents );
315319
316- return $ count ;
320+ // We return the total number of deletes for the operation. The developers
321+ // can then check this number as a boolean type value or get this total count
322+ // of records deleted for logging, etc.
323+ return count ($ ids );
324+ }
325+
326+ /**
327+ * Transform single ID, single Model or array of Models into an array of IDs
328+ *
329+ * @param mixed $ids
330+ * @return int
331+ */
332+ protected function getIdsArrayFrom ($ ids )
333+ {
334+ if (! is_array ($ ids )) $ ids = array ($ ids );
335+
336+ foreach ($ ids as &$ id )
337+ {
338+ if ($ id instanceof Model) $ id = $ id ->getKey ();
339+ }
340+
341+ return $ ids ;
317342 }
318343
319344 /**
0 commit comments