Laravel Mongo嵌入了许多不嵌入的文档


Laravel Mongo enbedsMany not embedding documents

使用经典的帖子和评论的例子,我看到的embedsMany关系似乎没有工作的地方,因为许多工作只是很好。这是与hasMany我看到外键和所有,但与embedsMany我看到没有嵌入的文档在Posts DB。

class Post extends Moloquent
{
    use SoftDeletes;
    /**
     * The name of the database connection to use.
     *
     * @var string
     */
    protected $connection = 'mongodb';

    public function comments()
    {
        return $this->embedsMany('App'Comment');
    }
}

class Comment extends Moloquent
{
    use SoftDeletes;
    /**
     * The name of the database connection to use.
     *
     * @var string
     */
    protected $connection = 'mongodb';

    /**
     * Get the case that owns the comment.
     */
    public function post()
    {
        return $this->belongsTo('App'Post');
    }

}

要保存的代码:

 $comment = new Comment();
  $comment->text = 'This is a comment';
  $comment->save();
  $post = new Post();
  $post->text='some text blah blah';
  $post->comments()->save($comment);

我明白了。我不应该保存评论文档。

 $comment = new Comment();
  $comment->text = 'This is a comment';
//  $comment->save();
  $post = new Post();
  $post->text='some text blah blah';
  $post->comments()->save($comment);