-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Righto lets say I have a BlogPost DomainObject that contains an ArrayField of Comments as follows.
class Comment extends Moa\DomainObject
{
}
class Post extends Moa\DomainObject
{
public function properties()
{
return array(
'comments' => new Moa\Types\ArrayField(array(
'type' => new Moa\Types\ReferenceField(array(
'type' => 'Comment'
)),
)),
);
}
}There is an issue where if I delete a comment from within that referenced field the post does not know it is gone until the LazyProperty is consumed in some way. For example:
Comment::remove(array('_id' => new \MongoId('someCommentId')));
$post = Post::findOne(array('_id' => new \MongoId('somePostId')));
echo count($post->comments); //prints 1 which is incorrect
echo isset($post->comments[0]); //prints 1 which is incorrect
echo $post->comments[0]; //prints nothing which is correct because it's deleted
foreach ($category->comments as $comment) {
echo $comment; //Wait what... how did you get here?
}The problem is the instance is not loaded until the array is referenced. It returns an array of lazy properties instead of an expected empty set that can cause some crazy bugs with iterators. Especially in twig!
I am not sure how to fix this issue without breaking lazy loading for everything else!
@lwc @alecsloman I'd be keen to hear your thoughts.
Reactions are currently unavailable