1

My Model:

use MongoDB\Laravel\Eloquent\Model;
use MongoDB\Laravel\Relations\EmbedsOne;

class TextContent extends Model {
    public function lock(): EmbedsOne
    {
        return $this->embedsOne (TextLock::class);
    }
}


class TextLock extends Model
{
}

This is how store a TextLock:

$lock = new TextLock();
$textContent->lock()->associate ($lock);
$textContent->save();

But I cannot delete it. I tried these methods:

$textContent->lock->delete();
$textContent->save();
// not working, $textContent->lock is still present
// weirdly: $textContent->lock has new prop named 'lock' after this operation. So we have $textContent->lock is `{lock: null}`
$textContent->lock()->delete();
// results in error: MongoDB\Laravel\Relations\EmbedsOne::delete(): Return value must be of type int, true returned
$textContent->lock = null;
$textContent->save();
// not working, $textContent->lock is still present

Any ideas?
I'm using this package: https://github.com/mongodb/laravel-mongodb

3
  • Are you using jenssegers/laravel-mongodb package or any other package?please specify. Commented May 1 at 10:03
  • @Subha it is the former jenssegers/laravel-mongodb package, in the meanwhile developers of mongodb overtook the maintaince, so it's mongodb/laravel-mongodb: github.com/mongodb/laravel-mongodb Commented May 1 at 10:47
  • Though I am not sure but after R&D of the docs it seems to me that instead of delete() you can try with dissociate().Don't forget to inform the outcome of this. Commented May 1 at 12:56

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.