我正在使用 symfony2 API 平台从我的 mongodb 数据库生成 api,但我收到此错误: hydra:description: "No resource found for object of type "AppBundle\Document\article"",
我有两个 mongo db 文档用户和文章,每个用户都有多篇文章,所以我试图列出所有用户及其所有文章标题,这样我就可以得到这样的东西:
{
@id: "/user/53edb6200cf2400d584c2617",
@type: "user",
class: "de.freelancer.mongo.domain.User",
email: "feer@de.com",
displayname: "feer",
withnewsletter: false,
language: "de_DE",
active: true,
admin: false,
articles : ['article1','article2','article3']
}
这是我的代码:
用户文档
<?php
namespace AppBundle\Document;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Validator\Constraints as Assert;
/**
@MongoDB\Document
@MongoDB\Document(collection="user")
/
class User{
/*
@MongoDB\Id(strategy="AUTO") */
private $id;
/**
@MongoDB\ReferenceMany(targetDocument="articles", mappedBy="user") */
private $articles;
public function __construct()
{
$this->articles = new ArrayCollection();
}
/**
*/
public function getArticles()
{
return $this->articles;
}
}
文章文件
<?php
namespace AppBundle\Document;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ODM\MongoDB\Mapping\Annotations as MongoDB;
use Dunglas\ApiBundle\Annotation\Iri;
use Symfony\Component\Validator\Constraints as Assert;
/**
@MongoDB\Document
@MongoDB\Document(collection="article")
/
class article
{
/*
@MongoDB\Id(strategy="AUTO") */
private $id;
/**
@MongoDB\ReferenceOne(targetDocument="user", inversedBy="articles") */
private $user;
/**
*/
public function setUser(userProfile $user)
{
$this->user = $user;
return $this;
}
/**
*/
public function getUser() {
return $this->user;
}
}
谁能帮我获取用户文章列表
谢谢