Skip to content

Fixed belongsToMany sync() #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 64 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
64 commits
Select commit Hold shift + click to select a range
3d6192a
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
da04754
Slimming down the BelongsToMany class
jenssegers Nov 20, 2013
485c25a
Tweaking BelongsToMany namespaces
jenssegers Nov 20, 2013
97e00b6
Small readme update for belongsToMany
jenssegers Nov 21, 2013
293fa5c
Markdown fixes
jenssegers Nov 21, 2013
e9b83e5
conflicts
Daveawb Nov 21, 2013
cc77fae
removed conflict
Daveawb Nov 21, 2013
062412a
Merge remote branch 'upstream/master'
Daveawb Nov 21, 2013
de0d889
removed settings
Daveawb Nov 21, 2013
fd5a470
updated gitgnore
Daveawb Nov 21, 2013
3b9b81a
README update
Daveawb Nov 25, 2013
e378c96
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
c797abd
Small readme update for belongsToMany
jenssegers Nov 21, 2013
46cbc34
Markdown fixes
jenssegers Nov 21, 2013
fb77334
conflicts
Daveawb Nov 21, 2013
d7da34b
removed conflict
Daveawb Nov 21, 2013
754216e
removed settings
Daveawb Nov 21, 2013
8d58aa0
updated gitgnore
Daveawb Nov 21, 2013
1f99417
Merge branch 'master' of github.com:DyeH/Laravel-MongoDB
Daveawb Nov 25, 2013
4885879
Fixed bug where related model doesn't have parent _id removed on sync
Daveawb Nov 27, 2013
706a3b8
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
4351a13
Small readme update for belongsToMany
jenssegers Nov 21, 2013
63ea245
conflicts
Daveawb Nov 21, 2013
a874d19
removed conflict
Daveawb Nov 21, 2013
6801149
removed settings
Daveawb Nov 21, 2013
be2e956
updated gitgnore
Daveawb Nov 21, 2013
6a7d264
README update
Daveawb Nov 25, 2013
9b9bd7c
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
b3ce53b
Small readme update for belongsToMany
jenssegers Nov 21, 2013
1fcf12e
Markdown fixes
jenssegers Nov 21, 2013
73edfab
conflicts
Daveawb Nov 21, 2013
3c1d049
removed conflict
Daveawb Nov 21, 2013
bd5c147
removed settings
Daveawb Nov 21, 2013
42dcd24
Fixed bug where related model doesn't have parent _id removed on sync
Daveawb Nov 27, 2013
9f4ed09
Merge branch 'master' of github.com:DyeH/Laravel-MongoDB
Daveawb Nov 27, 2013
b0bd0b2
Deleted merge file
Daveawb Nov 27, 2013
a9bed9a
Removed methods
Daveawb Nov 27, 2013
21a59dc
Readme re-updated
Daveawb Nov 27, 2013
1b7a84e
conflicts
Daveawb Nov 21, 2013
48b32cf
removed conflict
Daveawb Nov 21, 2013
0fdebc0
removed settings
Daveawb Nov 21, 2013
0213c71
updated gitgnore
Daveawb Nov 21, 2013
47d1d58
README update
Daveawb Nov 25, 2013
4a44c39
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
ceed9ef
conflicts
Daveawb Nov 21, 2013
0a0fa83
removed conflict
Daveawb Nov 21, 2013
b865d8a
removed settings
Daveawb Nov 21, 2013
dae8b71
Fixed bug where related model doesn't have parent _id removed on sync
Daveawb Nov 27, 2013
36cea2d
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
9428af0
Small readme update for belongsToMany
jenssegers Nov 21, 2013
d5ee4ce
conflicts
Daveawb Nov 21, 2013
c0ee666
removed conflict
Daveawb Nov 21, 2013
1b6093a
removed settings
Daveawb Nov 21, 2013
995710c
README update
Daveawb Nov 25, 2013
29ce2b5
Readme updated to show belongsToMany relationship availability
Daveawb Nov 21, 2013
db121a7
Small readme update for belongsToMany
jenssegers Nov 21, 2013
990960c
Markdown fixes
jenssegers Nov 21, 2013
09cb551
conflicts
Daveawb Nov 21, 2013
d3266c7
removed conflict
Daveawb Nov 21, 2013
2657b32
removed settings
Daveawb Nov 21, 2013
b6cba21
Deleted merge file
Daveawb Nov 27, 2013
9b2d939
Removed methods
Daveawb Nov 27, 2013
c185493
Readme re-updated
Daveawb Nov 27, 2013
74d4f7e
Merge branch 'master' of github.com:DyeH/Laravel-MongoDB
Daveawb Nov 27, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.DS_Store
phpunit.phar
/vendor
/.settings
composer.phar
composer.lock
*.sublime-project
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ If you are using a different database driver as the default one, you will need t
Everything else works just like the original Eloquent model. Read more about the Eloquent on http://laravel.com/docs/eloquent

### Optional: Alias
-------------------

You may also register an alias for the MongoDB model by adding the following to the alias array in `app/config/app.php`:

Expand Down Expand Up @@ -367,4 +368,4 @@ By default, Laravel keeps a log in memory of all queries that have been run for

DB::connection()->disableQueryLog();

*From: http://laravel.com/docs/database#query-logging*
*From: http://laravel.com/docs/database#query-logging*
11 changes: 9 additions & 2 deletions src/Jenssegers/Mongodb/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,16 @@ protected function createAttachRecords($ids, array $attributes)
public function detach($ids = array(), $touch = true)
{
if ($ids instanceof Model) $ids = (array) $ids->getKey();


// Generate a new parent query
$query = $this->newParentQuery();


// Generate a new related query instance
$related = $this->related->newInstance();

// Remove the relation from the related model
$related->pull($this->foreignKey, $this->parent->getKey());

// If associated IDs were passed to the method we will only delete those
// associations, otherwise all of the association ties will be broken.
// We'll return the numbers of affected rows when we do the deletes.
Expand Down
10 changes: 6 additions & 4 deletions tests/RelationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public function testHasManyAndBelongsToAttachesExistingModels()
);

$moreClients = array(
Client::create(array('name' => 'Boloni Ltd.'))->_id,
Client::create(array('name' => 'Meatballs Inc.'))->_id
Client::create(array('name' => 'synced Boloni Ltd.'))->_id,
Client::create(array('name' => 'synced Meatballs Inc.'))->_id
);

// Sync multiple records
Expand All @@ -209,7 +209,9 @@ public function testHasManyAndBelongsToAttachesExistingModels()

$user = User::with('clients')->find($user->_id);

// Assert there are now 4 client objects in the relationship
$this->assertCount(4, $user->clients);
// Assert there are now still 2 client objects in the relationship
$this->assertCount(2, $user->clients);
$this->assertStringStartsWith('synced', $user->clients[0]->name);
$this->assertStringStartsWith('synced', $user->clients[1]->name);
}
}