doutui6644 2017-04-07 10:16
浏览 18

在Symfony Doctrine中更新对象

I am stuck on my project and I want your help. I have 3 tables in my database (reviews, criteria and criteriaScope), I will showcase my code below. In reviews table I have 4 fields, id, review, score and total, where score and total can be null. Score is an array, where words are saved if any word in reviews is matched with a word in the criteria table and total is the count of the positive or negative words in the score field.

In my index view I show all the reviews(without the score and total) and I have a button and when pressed I want

1) to update my database to find the matched words and set them in the score field and,

2) to update the total field respectively to the words from the score field.

Here is my code:

Reviews entity

class reviews

/**
 * @var int
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="review", type="string", length=500)
 */
private $review;

/**
 * @var array
 *
 * @ORM\Column(name="score", type="array", nullable=true)
 */
private $score;

/**
 * @var int
 *
 * @ORM\Column(name="total", type="integer", nullable=true)
 */
private $total;

and the getters/setters..

Criteria Entity

**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 *
 * @ORM\Column(name="topic", type="string", length=30)
 */
private $topic;

/**
 * @ORM\OneToMany(targetEntity="criteriaScope", mappedBy="criteria", cascade={"persist"})
 */
private $criteriaScope;

and getters/setters

CriteriaScope Entity

/**
 * @var int
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

/**
 * @var string
 * @ORM\Column(name="positives", type="string", length=50)
 */
private $positives;

/**
 * @var string
 *
 * @ORM\Column(name="negatives", type="string", length=50)
 */
private $negatives;

/**
* @ORM\ManyToOne(targetEntity="criteria", inversedBy="criteriaScope", cascade={"persist"})
* @ORM\JoinColumn(name="criteria_id", referencedColumnName="id")
*/
private $criteria;

plus the getters/setters

So what I want to do is, in my analyzedAction, to compare each review with each criteriaScope.positive and criteriaScope.negative, and update my score and total field in reviews database.

Thank you in advance :)

P.S: I am using Symfony 2.8

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 基于卷积神经网络的声纹识别
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图
    • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
    • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
    • ¥15 一直显示正在等待HID—ISP
    • ¥15 Python turtle 画图