ユーザーに関連付けられているすべてのフォロワーを取得したいのですが、特定のルールがあります。タイプ 0 のもののみ。次の表からフォロワーを取得するユーザー エンティティ メソッドを次に示します。
/**
* @ORM\OneToMany(targetEntity="Follow", mappedBy="following")
*/
protected $followers;
---------------
/**
* Add Followers
*
* @param \Acme\UserBundle\Entity\Follow $follow
* @return DealFlowCore
*/
public function addFollower(\Acme\UserBundle\Entity\Follow $followers)
{
$this->followers[] = $followers;
return $this;
}
/**
* Remove Followers
*
* @param \Acme\UserBundle\Entity\Follow $followers
*/
public function removeFollower(\Acme\UserBundle\Entity\Follow $followers)
{
$this->followers->removeElement($followers);
}
/**
* Get Followers
*
* @return \Doctrine\Common\Collections\Collection
*/
public function getFollowers()
{
return $this->followers;
}
ここにフォローエンティティがあります
<?php
namespace Acme\UserBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* FFollow
*
* @ORM\Table(name="f_follow")
* @ORM\Entity
*/
class Follow
{
/**
* @var integer
*
* @ORM\Column(name="id_follow", type="integer", nullable=false)
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var integer // 0 user 1 project
*
* @ORM\Column(name="type_follow", type="integer", nullable=false)
*/
private $typeFollow;
/**
* @var \DateTime
*
* @ORM\Column(name="date", type="datetime", nullable=false)
*/
private $date;
/**
* @var \FUser
*
* @ORM\ManyToOne(targetEntity="User", inversedBy="followers")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_following", referencedColumnName="id")
* })
*/
private $following;
/**
* @var \FUser
*
* @ORM\ManyToOne(targetEntity="User")
* @ORM\JoinColumns({
* @ORM\JoinColumn(name="id_follower", referencedColumnName="id")
* })
*/
private $follower;
public function __construct($typeFollow = 0)
{
$this->typeFollow = $typeFollow;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set typeFollow
*
* @param integer $typeFollow
* @return Follow
*/
public function setTypeFollow($typeFollow)
{
$this->typeFollow = $typeFollow;
return $this;
}
/**
* Get typeFollow
*
* @return integer
*/
public function getTypeFollow()
{
return $this->typeFollow;
}
/**
* Set date
*
* @param \DateTime $date
* @return Follow
*/
public function setDate($date)
{
$this->date = $date;
return $this;
}
/**
* Get date
*
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
/**
* Set following
*
* @param \Acme\UserBundle\Entity\User $following
* @return Follow
*/
public function setFollowing(\Acme\UserBundle\Entity\User $following = null)
{
$this->following = $following;
return $this;
}
/**
* Get following
*
* @return \Acme\UserBundle\Entity\User
*/
public function getFollowing()
{
return $this->following;
}
/**
* Set follower
*
* @param \Acme\UserBundle\Entity\User $follower
* @return Follow
*/
public function setFollower(\Acme\UserBundle\Entity\User $follower = null)
{
$this->follower = $follower;
return $this;
}
/**
* Get follower
*
* @return \Acme\UserBundle\Entity\User
*/
public function getFollower()
{
return $this->follower;
}
}