【发布时间】:2015-04-18 10:13:25
【问题描述】:
我正在创建一个将 cmets 添加到 Sylius 中的产品的功能。
所以我在src/Sylius/Component/Product/Model/CommentProduct.php中创建了一个新模型CommentProduct
我为CommentProduct定义了ORM映射:
<?xml version="1.0" encoding="utf-8"?>
<doctrine-mapping
xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:gedmo="http://gediminasm.org/schemas/orm/doctrine-extensions-mapping"
xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping
http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"
>
<mapped-superclass name="Sylius\Component\Product\Model\CommentProduct" table="sylius_product_comment">
<id name="id" type="integer" column="id">
<generator strategy="AUTO"/>
</id>
<field name="createdAt" type="datetime" column="created_at">
<gedmo:timestampable on="create"/>
</field>
<field name="updatedAt" type="datetime" column="updated_at" nullable="true">
<gedmo:timestampable on="update"/>
</field>
<field name="commentParentId" type="integer" column="comment_parent_id"/>
<field name="commentText" type="string" column="comment_text" length="1000"/>
<field name="userId" type="integer" column="created_by"/>
<many-to-one field="product" target-entity="Sylius\Component\Product\Model\ProductInterface" inversed-by="comments">
<join-column name="product_id" referenced-column-name="id" nullable="false" />
</many-to-one>
</mapped-superclass>
</doctrine-mapping>
在Product.orm.xml 中,我为产品和评论添加了一对多关系
<one-to-many field="comments" target-entity="Sylius\Component\Product\Model\CommentProduct" mapped-by="product" orphan-removal="true">
<cascade>
<cascade-all/>
</cascade>
</one-to-many>
所以现在我想为模型ProductComment 建立一个存储库,我看到另一个存储库,它的调用方式如下:
$country = $this->get('sylius.repository.country');
但是当我打电话时:
$commentRepo = $this->container->get('sylius.repository.commentproduct');
我有一个例外:
您请求了一个不存在的服务“sylius.repository.commentproduct”。
所以我必须做一些事情来拥有我的模型的存储库?有人可以帮助我吗?非常感谢
【问题讨论】:
标签: model doctrine repository entity sylius