Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.1.2
-
Fix Version/s: 2.1.3
-
Component/s: None
-
Security Level: All
-
Labels:None
Description
/**
* @Entity
*/
class Article
{
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/**
* @OneToMany(targetEntity="UserState", mappedBy="article", indexBy="userId", fetch="EXTRA_LAZY")
*/
protected $userStates;
.......
}
/**
* @Entity
*/
class User
{
/**
* @Id
* @Column(type="integer")
*/
protected $id;
/**
* @OneToMany(targetEntity="UserState", mappedBy="user", indexBy="articleId", fetch="EXTRA_LAZY")
*/
protected $userStates;
.......
}
/**
* @Entity
*/
class UserState
{
/**
* @Id
* @ManyToOne(targetEntity="Article", inversedBy="userStates")
*/
protected $article;
/**
* @Id
* @ManyToOne(targetEntity="User", inversedBy="userStates")
*/
protected $user;
/**
* @Column(name="user_id", type="integer")
*/
protected $userId;
/**
* @Column(name="article_id", type="integer")
*/
protected $articleId;
/**
* @Column(type="boolean")
*/
protected $hasLiked;
.......
}
$q = $em->createQuery("SELECT a, s FROM Article a JOIN a.userStates s WITH s.user = :activeUser");
$q->setParameter('activeUser', $activeUserId);
$q->getResult();
if i $em->flush() now it will execute lots of update queries like:
UPDATE userstate SET article_id = ? WHERE user_id = ? AND article_id = ?
I think your mapping is wrong. You cannot map an @Id + @ManyToOne and then remap the same column using @Column.
What exactly are the parameters to the query? How is it updating article_id ?
Is this even affected by "indexBy"? Can you remove them and try again?