mongodb / laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel (Moloquent)
https://www.mongodb.com/docs/drivers/php/laravel-mongodb/
MIT License
7.01k stars 1.43k forks source link

[Question] belongsToMany, hybrid relation and detach #2002

Closed RaGreen closed 4 years ago

RaGreen commented 4 years ago

I have two models (yep I noticed about belongsToMany and HybridRelation):

  1. User - MySQL model with use HybridRelation and relation belongsToMany of Role
  2. Role - MongoDB model without HybridRelation and relation belongsToMany of User

$user is attached to multiple ->roles(). Ids are stored in Role model only.

I try to detach $role from $user via: $user->roles()->detach($role->_id)

It throws an exception: BadMethodCallException: Call to undefined method App\Models\User::pull() because Illuminate\Database\Eloquent\Model doesn't contain pull() method, when Jenssegers\Mongodb\Eloquent\Model has it.

Attach ($user->roles()->attach($role->_id)) works correctly. What i'm doing wrong?

Lumen: 6.0 Jenssegers/mongodb: 3.6

Smolevich commented 4 years ago

@RaGreen , describe full version of laravel-mongodb, for example 3.6.1