drsdvwsvo78320812 2014-09-08 13:07
浏览 46
已采纳

仅在sonata管理视图中加载ManyToMany属性

i'm using sonata admin for managing entities in my symfony application. the entities have some many to many properties, and i want to administrate them in sonata. therefore i added this to the entity:

/**
 * @ORM\ManyToMany(targetEntity="Product", inversedBy="farmer", cascade={"persist"})
 * @ORM\JoinTable(name="farmerproduct",
 *     joinColumns={
 *     @ORM\JoinColumn(name="farmer_id", referencedColumnName="id")
 *   },
 *   inverseJoinColumns={
 *     @ORM\JoinColumn(name="product_id", referencedColumnName="id")
 *   }
 * )
 */
private $products;

The problem now is that in my application, I'm fetching lots of these farmers (the entity) and this ends up in a PHP Fatal error: Allowed memory size of 134217728 bytes exhausted

The reason is, I'm sending the results to the web application through JSON.

How can I use the products only in sonata admin only? I have already programmed some lazy loading style fetching of the products in a next step. So i don't need it in my webapplication.

Any ideas?

  • 写回答

2条回答 默认 最新

  • duanlanqian9974 2014-09-08 23:53
    关注

    Okay the problem was easily solved

    First Way to do is with the setIgnored method of the serializer: http://symfony.com/doc/current/components/serializer.html#ignoring-attributes-when-serializing

    If this does not work (as it didn't work for me), second way is:

    Second way: Create a new entity object only for administration and add the manytomany in that entity, reconfigure your sonata admin config in admin.yml to work with the new entity which is mapped to the original entity in the database. Use your old entity for webapp.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效