laravel-mongodb icon indicating copy to clipboard operation
laravel-mongodb copied to clipboard

Timestamps not hydrated on embedded models

Open Rezouce opened this issue 10 years ago • 7 comments

<?php
class Model extends \Jenssegers\Mongodb\Model
{
    public function association()
    {
        return $this->embedsMany('ModelChild');
    }
}

class ModelChild extends \Jenssegers\Mongodb\Model
{
}

$model = new Model;
$child = new ChildModel;

$model->association()->associate($child);
$model->save(); // The child's timestamps ARE NOT hydrated


$model = new Model;
$child = new ChildModel;

$model->save();
$model->association()->save($child); // The child's timestamps ARE hydrated

The result should have been the same regardless the way we saved the model (preferably, the timestamps should be there is both cases).

Rezouce avatar Sep 21 '15 12:09 Rezouce

Can confirm, had the same problem. The save() saves the timestamps while associate() does not.

ghost avatar Aug 09 '16 19:08 ghost

The issue is still relevant using v3.4.6.

@jenssegers, any comments? Maybe something was analyzed and some conclusions were made before closing this issue back in 2018? 🙂

aleksandrs-eigims avatar Apr 15 '20 06:04 aleksandrs-eigims

The issue is still relevant using v3.4.6.

@jenssegers, any comments? Maybe something was analyzed and some conclusions were made before closing this issue back in 2018? 🙂

@lllypa you can create issue with description and demonstration problem. We are open for community

Smolevich avatar Apr 15 '20 07:04 Smolevich

@Smolevich, sure. I was thinking of understanding the reason for closing this one first, before opening the same one again. Or re-opening this one, as the description would be a duplicate - I am still having the exact issue @Rezouce described in this issue.

aleksandrs-eigims avatar Apr 15 '20 07:04 aleksandrs-eigims

Embed model is old functional that can consist many bugs

Smolevich avatar Apr 15 '20 08:04 Smolevich

Embed model is old functional that can consist many bugs

@Smolevich, is there any new/alternative "best practice" for embedded documents then? I mean, "embedded documents" is an inseparable part of MongoDB. How else one could describe it in Eloquent?

aleksandrs-eigims avatar Apr 15 '20 12:04 aleksandrs-eigims

I am also wondering, if this isn't best practise, it should be removed from the docs.

mattg66 avatar Apr 06 '21 16:04 mattg66