I have a small misunderstanding in how the joining in Doctrine2 work.
We have a pretty complex structure in our app and we are building management screens for it.
The area of concern is as follows:
Once of the objects 'Application' looks like this:
class Application
{
/**
* List of supported statuses
*
* #var array
*/
private $statuses = array('released', 'expired');
/**
*
* #var integer $id
*
* #Column(name="id", type="integer", columnDefinition="INT(10) UNSIGNED")
* #Id
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #Column(name="Name", type="string", length=100)
*/
private $name;
/**
* #var Customer
*
* #ManyToOne(targetEntity="libraries\persona\Entity\Customer")
* #JoinColumn(name="Customers_id", referencedColumnName="id", nullable=true, columnDefinition="INT(10) UNSIGNED")
*/
private $customer;
/**
* #var integer
*
* #Column(name="Partners_id", type="integer", nullable=true)
*/
private $partnerId;
/**
* #var string
*
* #Column(name="appID", type="string", length=48)
*/
private $appId;
/**
* #var string
*
* #Column(name="status", type="string", length=15)
*/
private $status;
/**
* #var \DateTime
*
* #Column(name="eventStartDate", type="date")
*/
private $eventStartDate;
/**
* #var \DateTime
*
* #Column(name="eventEndDate", type="date")
*/
private $eventEndDate;
/**
* #var string
*
* #Column(name="timeZone", type="string", length=45)
*/
private $timeZone;
/**
* #ManyToOne(targetEntity="libraries\application\Entity\ApplicationType", inversedBy="applications")
* #JoinColumn(name="ApplicationTypes_id", referencedColumnName="id")
*/
private $applicationType;
/**
* #var integer
*
* #Column(name="syncPeriod", type="integer", length=10, nullable=true)
*/
private $syncPeriod;
/**
* #var \DateTime
*
* #Column(name="lastSync", type="datetime", nullable=true)
*/
private $lastSync;
/**
* #var string
*
* #Column(name="lastSyncStatus", type="string", length=127, nullable=true)
*/
private $lastSyncStatus;
/**
* #var string
*
* #Column(name="syncScript", type="string", length=250, nullable=true)
*/
private $syncScript = '/var/www/quickstart/application/controllers/scripts/qdissync.php';
/**
* #var integer
*
* #Column(name="size", type="integer", length=10)
*/
private $size = 400;
/**
* #var text
*
* #Column(name="metaData", type="text", nullable=true)
*/
private $metaData;
/**
* #var \DateTime
*
* #Column(name="metaDataChangedTime", type="datetime", nullable=true)
*/
private $metaDataChangedTime;
/**
* #var tinyint
*
* #Column(name="isSecure", type="smallint", length=1)
*/
private $isSecure = 2;
/**
* #var integer
*
* #Column(name="Users_id", type="integer", nullable=true)
*/
private $userId;
/**
* #var string
*
* #Column(name="singleEventAppId", type="string", length=48, nullable=true)
*/
private $singleEventAppId;
/**
* #var string
*
* #Column(name="project_db", type="string", length=50)
*/
private $projectDb;
/**
* #var string
*
* #Column(name="appName", type="string", length=12)
*/
private $appName;
/**
* #var boolean
*
* #Column(name="mobileLog", type="boolean")
*/
private $mobileLog = false;
/**
* #var tinyint
*
* #Column(name="eventType", type="smallint", length=1)
*/
private $eventType = 1;
/**
* #ManyToOne(targetEntity="libraries\application\Entity\Project", inversedBy="applications")
* #JoinColumn(name="project_id", referencedColumnName="id")
*/
private $project;
/**
* #OneToMany(targetEntity="libraries\platform\Entity\Platform", mappedBy="application")
**/
private $platforms;
/**
* #var SnapEventAttributes
*
* #OneToOne(targetEntity="libraries\application\Entity\SnapEventAttributes", mappedBy="application")
**/
private $snapEventAttributes;
//GETTERS & SETTERS
}
One of the related objects 'SnapEventAttributes':
class SnapEventAttributes
{
/**
*
* #var integer
*
* #Column(name="id", type="integer", columnDefinition="INT(11)")
* #Id
* #GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* #var string
*
* #Column(name="directSelectId", type="string", length=10, nullable=true)
*/
private $directSelectId;
/**
* #var string
*
* #Column(name="description", type="text", nullable=true)
*/
private $description;
/**
* #var string
*
* #Column(name="access", type="string", length=10, nullable=false)
*/
private $access;
/**
* #var string
*
* #Column(name="status", type="string", length=10, nullable=false)
*/
private $status;
/**
* #var string
*
* #Column(name="snapAppVersion", type="string", length=5, nullable=true)
*/
private $snapAppVersion;
/**
* #var string
*
* #Column(name="pwd", type="string", length=250, nullable=true)
*/
private $password;
/**
* #var string
*
* #Column(name="thumbnailUrl", type="string", length=250, nullable=true)
*/
private $thumbnailUrl;
/**
* #var string
*
* #Column(name="location", type="string", length=45, nullable=true)
*/
private $location;
/**
* #OneToOne(targetEntity="libraries\application\Entity\Application", inversedBy="snapEventAttributes")
* #JoinColumn(name="Applications_id", referencedColumnName="id", unique=true, nullable=false)
*/
private $application;
// GETTERS & SETTERS
}
In one of our work flows we need to join these two with bunch of additional joins and we got something like this:
$qb = $this->createQueryBuilder('e');
$qb->innerJoin('e.applicationType', 'et', Expr\Join::WITH, 'et.mobileEvent = :mobileEvent AND et.snapApp = :snapApp AND et.snapEvent = :snapEvent');
$qb->innerJoin('e.snapEventAttributes', 'attrs');
$qb->innerJoin('e.project', 'p');
$qb->innerJoin('p.applications', 'a');
$qb->innerJoin('a.applicationType', 'at', Expr\Join::WITH, 'at.mobileEvent = :vMobileEvent AND at.snapApp = :vSnapApp AND at.snapEvent = :vSnapEvent');
$qb->leftJoin('e.customer', 'cust');
$qb->leftJoin('p.partner', 'partn');
$qb->setParameters(array(
'mobileEvent' => false,
'snapApp' => false,
'snapEvent' => true,
'vMobileEvent' => false,
'vSnapApp' => true,
'vSnapEvent' => false,
));
return $qb;
All the logic works perfectly fine, however once I execute this query:
$qb->getQuery()->getResult();
the main query is getting executed as expected but automatically doctrine executes bunch of queries to get the SnapEventAttributes objects:
SELECT t0.id AS id1, t0.directSelectId AS directSelectId2, t0.description AS description3, t0.access AS access4, t0.status AS status5, t0.snapAppVersion AS snapAppVersion6, t0.pwd AS pwd7, t0.thumbnailUrl AS thumbnailUrl8, t0.location AS location9, t0.Applications_id AS Applications_id10 FROM SnapEventAttributes t0 WHERE t0.Applications_id = ?
What am I missing? What could be a reason for this behavior?
Thanks,
A.
get the repository
Controller
$snapEvents = $this->em->snapEvents ( 'Entity\SnapEventAttributes' )->findAll ();
$data ['snapEvents '] = $snapEvents ;
then on the view
View
foreach ($snapEvents $sanpEvent) {
echo "<tr>".
"<td>" . $sanpEvent->getAppliction()->getApplicationType() . "</td>".
"<td>" . $sanpEvent->getAppliction()->getCutomer() . "</td>".
}
Like this keep on calling what u want since u have already joined columns at the model
I am currently making a website and I have an entity User, which has several fields. But when I am trying retrieve the current user that is logged in it only retrieves the username.
Fields in UserType are as follows:
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email')
->add('name')
->add('building')
->add('room')
;
}
I am using this html code and TWIG to retrieve the fields:
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Building</th>
<th>Room Number</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ app.user.name }}</td>
<td>{{ app.user.building }}</td>
<td>{{ app.user.room }}</td>
<td>{{ app.user.email }}</td>
</tr>
</tbody>
</table>
But when I view table in the browser I only get the email field populated in the table?
User Entity:
<?php
namespace FYProject\ProjectBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
*
* #ORM\Entity
* #ORM\Table(name="fyp_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*/
protected $username;
/**
* #var string
*/
protected $password;
/**
* #var string
*/
protected $name;
/**
* #var string
*/
protected $lastname;
/**
* #var string
*/
protected $school;
/**
* #var string
*/
protected $qualification;
/**
* #var string
*/
protected $modeofstudy;
/**
* #var string
*/
protected $programmecode;
/**
* #var integer
*/
protected $programmeyear;
/**
* #var datetime
*/
protected $startdate;
/**
* #var string
*/
protected $building;
/**
* #var integer
*/
protected $room;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set username
*
* #param string $username
* #return Entity
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* #return string
*/
public function getUsername()
{
return $this->username;
}
/**
* Set password
*
* #param string $password
* #return Entity
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set name
*
* #param string $name
* #return Entity
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set school
*
* #param string $school
* #return Entity
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* #return string
*/
public function getSchool()
{
return $this->school;
}
/**
* set qualification
*
* #param string qualification
* #return Entity
*/
public function setQualification($qualification){
$this->qualification = $qualification;
return $this;
}
/**
* get qualification
*
* #return string
*/
public function getQualification(){
return $this->qualification;
}
/**
* set modeofstudy
*
* #param string modeofstudy
* #return Entity
*/
public function setModeofstudy($modeofstudy){
$this->modeofstudy = $modeofstudy;
return $this;
}
/**
* get modeofstudy
*
* #return string
*/
public function getModeofstudy(){
return $this->modeofstudy;
}
/**
* set programmecode
*
* #param string programmecode
* #return Entity
*/
public function setProgrammecode($programmecode){
$this->programmecode = $programmecode;
return $this;
}
/**
* get programmecode
*
* #return string
*/
public function getProgrammecode(){
return $this->programmecode;
}
/**
* set programmeyear
*
* #param integer programmeyearn
* #return Entity
*/
public function setProgrammeyear($programmeyear){
$this->programmecode = $programmeyear;
return $this;
}
/**
* get programmecode
*
* #return integer
*/
public function getProgrammeyear(){
return $this->programmeyear;
}
/**
* set startdate
*
* #param datetime startdate
* #return Entity
*/
public function setStartdate($startdate){
$this->startdate = $startdate;
return $this;
}
/**
* get startdate
*
* #return datetime
*/
public function getStartdate(){
return $this->startdate;
}
/**
* set lastname
*
* #param string lastname
* #return Entity
*/
public function setLastname($lastname){
$this->lastname = $lastname;
return $this;
}
/**
* get lastname
*
* #return string
*/
public function getLastname(){
return $this->lastname;
}
/**
* set building
* #param string building
* #return Entity
*/
public function setBuilding($building){
$this->building = $building;
return $this;
}
/**
* get building
*
* #return string
*/
public function getBuilding(){
return $this->building;
}
/**
* set room
* #param integer room
* #return Entity
*/
public function setRoom($room){
$this->room = $room;
return $this;
}
/**
* get room
*
* #return integer
*/
public function getRoom(){
return $this->room;
}
public function __construct(){
parent::__construct();
}
}
When registering the current fields are returning null, using dump(app.user):
User {#306 ▼
#id: 9
#name: null
#lastname: null
#school: null
#qualification: null
#modeofstudy: null
#programmecode: null
#programmeyear: null
#startdate: null
#building: null
#room: null
Use this docummentation to override a Form Type
https://github.com/FriendsOfSymfony/FOSUserBundle/blob/master/Resources/doc/overriding_forms.md
Update your database schema
Clear your cache
Problem solved
I wasnt setting the #ORM\column for each field in the Entity User. Updated User Entity:
<?php
namespace FYProject\ProjectBundle\Entity;
use FOS\UserBundle\Model\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
/**
*
* #ORM\Entity
* #ORM\Table(name="fyp_user")
*/
class User extends BaseUser
{
/**
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* #var string
*
* #ORM\Column(name="name", type="string", length=100)
*
*/
protected $name;
/**
* #var string
*
* #ORM\Column(name="lastname", type="string", length=100)
*/
protected $lastname;
/**
* #var string
*
* #ORM\Column(name="school", type="string", length=100)
*/
protected $school;
/**
* #var string
*
* #ORM\Column(name="qualification", type="string", length=50)
*/
protected $qualification;
/**
* #var string
*
* #ORM\Column(name="modeofstudy", type="string", length=50)
*/
protected $modeofstudy;
/**
* #var string
*
* #ORM\Column(name="programmecode", type="string", length=50)
*/
protected $programmecode;
/**
* #var integer
*
* #ORM\Column(name="programmeyear", type="integer", length=10)
*/
protected $programmeyear;
/**
* #var datetime
*
* #ORM\Column(name="startdate", type="datetime", length=50)
*/
protected $startdate;
/**
* #var string
*
* #ORM\Column(name="building", type="string", length=50)
*/
protected $building;
/**
* #var integer
*
* #ORM\Column(name="room", type="integer", length=50)
*/
protected $room;
/**
* Get id
*
* #return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set name
*
* #param string $name
* #return Entity
*/
public function setName($name)
{
$this->name = $name;
return $this;
}
/**
* Get name
*
* #return string
*/
public function getName()
{
return $this->name;
}
/**
* Set school
*
* #param string $school
* #return Entity
*/
public function setSchool($school)
{
$this->school = $school;
return $this;
}
/**
* Get school
*
* #return string
*/
public function getSchool()
{
return $this->school;
}
/**
* set qualification
*
* #param string $qualification
* #return Entity
*/
public function setQualification($qualification){
$this->qualification = $qualification;
return $this;
}
/**
* get qualification
*
* #return string
*/
public function getQualification(){
return $this->qualification;
}
/**
* set modeofstudy
*
* #param string $modeofstudy
* #return Entity
*/
public function setModeofstudy($modeofstudy){
$this->modeofstudy = $modeofstudy;
return $this;
}
/**
* get modeofstudy
*
* #return string
*/
public function getModeofstudy(){
return $this->modeofstudy;
}
/**
* set programmecode
*
* #param string $programmecode
* #return Entity
*/
public function setProgrammecode($programmecode){
$this->programmecode = $programmecode;
return $this;
}
/**
* get programmecode
*
* #return string
*/
public function getProgrammecode(){
return $this->programmecode;
}
/**
* set programmeyear
*
* #param integer $programmeyear
* #return Entity
*/
public function setProgrammeyear($programmeyear){
$this->programmecode = $programmeyear;
return $this;
}
/**
* get programmecode
*
* #return integer
*/
public function getProgrammeyear(){
return $this->programmeyear;
}
/**
* set startdate
*
* #param datetime $startdate
* #return Entity
*/
public function setStartdate($startdate){
$this->startdate = $startdate;
return $this;
}
/**
* get startdate
*
* #return datetime
*/
public function getStartdate(){
return $this->startdate;
}
/**
* set lastname
*
* #param string $lastname
* #return Entity
*/
public function setLastname($lastname){
$this->lastname = $lastname;
return $this;
}
/**
* get lastname
*
* #return string
*/
public function getLastname(){
return $this->lastname;
}
/**
* set building
* #param string $building
* #return Entity
*/
public function setBuilding($building){
$this->building = $building;
return $this;
}
/**
* get building
*
* #return string
*/
public function getBuilding(){
return $this->building;
}
/**
* set room
* #param integer $room
* #return Entity
*/
public function setRoom($room){
$this->room = $room;
return $this;
}
/**
* get room
*
* #return integer
*/
public function getRoom(){
return $this->room;
}
public function __construct(){
parent::__construct();
}
}
Problem Solved! Thanks for the help!
This is my Doctrine2 Annotation file, which is returning me this error
MappingException: No identifier/primary key specified for Entity
"WbsGo\clientsBundle\Entity\VtigerPortalinfo". Every Entity must have
an identifier/primary key.
In DB, the field ID is set to Primary Key... So I don't know where is the problem....
<?php
namespace WbsGo\clientsBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* VtigerPortalinfo
*/
class VtigerPortalinfo
{
/**
* #var string
*/
private $userName;
/**
* #var string
*/
private $userPassword;
/**
* #var string
*/
private $type;
/**
* #var \DateTime
*/
private $lastLoginTime;
/**
* #var \DateTime
*/
private $loginTime;
/**
* #var \DateTime
*/
private $logoutTime;
/**
* #var integer
*/
private $isactive;
/**
* #var \WbsGo\clientsBundle\Entity\VtigerContactdetails
* #ORM\Id
* #ORM\Column(type="integer")
* #ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* Set userName
*
* #param string $userName
* #return VtigerPortalinfo
*/
public function setUserName($userName)
{
$this->userName = $userName;
return $this;
}
/**
* Get userName
*
* #return string
*/
public function getUserName()
{
return $this->userName;
}
/**
* Set userPassword
*
* #param string $userPassword
* #return VtigerPortalinfo
*/
public function setUserPassword($userPassword)
{
$this->userPassword = $userPassword;
return $this;
}
/**
* Get userPassword
*
* #return string
*/
public function getUserPassword()
{
return $this->userPassword;
}
/**
* Set type
*
* #param string $type
* #return VtigerPortalinfo
*/
public function setType($type)
{
$this->type = $type;
return $this;
}
/**
* Get type
*
* #return string
*/
public function getType()
{
return $this->type;
}
/**
* Set lastLoginTime
*
* #param \DateTime $lastLoginTime
* #return VtigerPortalinfo
*/
public function setLastLoginTime($lastLoginTime)
{
$this->lastLoginTime = $lastLoginTime;
return $this;
}
/**
* Get lastLoginTime
*
* #return \DateTime
*/
public function getLastLoginTime()
{
return $this->lastLoginTime;
}
/**
* Set loginTime
*
* #param \DateTime $loginTime
* #return VtigerPortalinfo
*/
public function setLoginTime($loginTime)
{
$this->loginTime = $loginTime;
return $this;
}
/**
* Get loginTime
*
* #return \DateTime
*/
public function getLoginTime()
{
return $this->loginTime;
}
/**
* Set logoutTime
*
* #param \DateTime $logoutTime
* #return VtigerPortalinfo
*/
public function setLogoutTime($logoutTime)
{
$this->logoutTime = $logoutTime;
return $this;
}
/**
* Get logoutTime
*
* #return \DateTime
*/
public function getLogoutTime()
{
return $this->logoutTime;
}
/**
* Set isactive
*
* #param integer $isactive
* #return VtigerPortalinfo
*/
public function setIsactive($isactive)
{
$this->isactive = $isactive;
return $this;
}
/**
* Get isactive
*
* #return integer
*/
public function getIsactive()
{
return $this->isactive;
}
/**
* Set id
*
* #param \WbsGo\clientsBundle\Entity\VtigerContactdetails $id
* #return VtigerPortalinfo
*/
public function setId(\WbsGo\clientsBundle\Entity\VtigerContactdetails $id = null)
{
$this->id = $id;
return $this;
}
/**
* Get id
*
* #return \WbsGo\clientsBundle\Entity\VtigerContactdetails
*/
public function getId()
{
return $this->id;
}
}
Maybe if you change the annotation line of $id for this line:
*ORM\GeneratedValue(strategy="IDENTITY")
Is there a way to access a joined entity's relation in the WITH clause of a join? Im trying to avoid using an IN clause with a subquery.
Edit: Or is there a way to join on a subquery rather than using IN?
i.e. Making sure the joined object's t.final value is 1.
Trying to Avoid This Query
SELECT o
FROM Entity\Order o
WHERE o.status = :orderStatus
AND o.id NOT IN (
SELECT o2.id
FROM Entity\ServiceRequest s
JOIN s.order o2
JOIN s.serviceType t
WHERE s.status = :serviceStatus
AND t.final = 1
)
Failing Rewrite Attempt:
Not able to access s.serviceType.final
SELECT o
FROM Entity\Order o
LEFT JOIN o.serviceRequests s
WITH s.status = :serviceStatus
AND s.serviceType.final = 1
LEFT JOIN s.serviceType t
WHERE o.status = :orderStatus
AND COUNT(s) = 0
Order Entity:
<?php
namespace Entity;
/**
* #Entity(repositoryClass="Repository\Order")
* #Table(name="orders")
*/
class Order
{
const STATUS_REVIEW = 0;
const STATUS_PENDING = 1;
const STATUS_SCHEDULED = 2;
const STATUS_COMPLETE = 3;
/**
* #Id
* #Column(type="integer")
* #GeneratedValue
*
* #var int
*/
protected $id;
/**
* #ManyToOne(targetEntity="Invoice")
*
* #var Invoice
*/
protected $invoice;
/**
* #Column(type="integer")
*
* #var int
*/
protected $status;
/**
* #Column(type="smallint", name="is_canceled")
*
* #var int
*/
protected $isCanceled;
/**
* #OneToMany(targetEntity="ServiceRequest", mappedBy="order")
*
* #var ServiceRequest[]
*/
protected $serviceRequests;
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #return \Entity\Invoice
*/
public function getInvoice()
{
return $this->invoice;
}
/**
* #return int
*
* #uses \Entity\Order::STATUS_REVIEW
* #uses \Entity\Order::STATUS_PENDING
* #uses \Entity\Order::STATUS_SCHEDULED
* #uses \Entity\Order::STATUS_COMPLETE
*/
public function getStatus()
{
return $this->status;
}
/**
* #param int $status
*
* #uses \Entity\Order::STATUS_REVIEW
* #uses \Entity\Order::STATUS_PENDING
* #uses \Entity\Order::STATUS_SCHEDULED
* #uses \Entity\Order::STATUS_COMPLETE
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* #return int
*/
public function getIsCanceled()
{
return $this->isCanceled;
}
public function cancel()
{
$this->isCanceled = 1;
}
/**
* #return ServiceRequest[]
*/
public function getServices()
{
return $this->services;
}
}
ServiceRequest Entity:
/**
* #Entity
* #Table(name="order_service_requests")
*/
class ServiceRequest
{
const STATUS_REVIEW = 0;
const STATUS_PENDING = 1;
const STATUS_SCHEDULED = 2;
const STATUS_COMPLETE = 3;
/**
* #Id
* #Column(type="integer")
* #GeneratedValue
*
* #var int
*/
protected $id;
/**
* #ManyToOne(targetEntity="Invoice")
*
* #var Invoice
*/
protected $invoice;
/**
* #ManyToOne(targetEntity="ServiceType")
* #JoinColumn(name="service_types_id")
*
* #var ServiceType
*/
protected $serviceType;
/**
* #ManyToOne(targetEntity="Order")
* #JoinColumn(name="orders_id")
*
* #var Order
*/
protected $order;
/**
* #Column(type="integer")
*
* #var int
*/
protected $status;
/**
* #Column(type="smallint", name="is_canceled")
*
* #var int
*/
protected $isCanceled;
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #return \Entity\Invoice
*/
public function getInvoice()
{
return $this->invoice;
}
/**
* #return int
*
* #uses \Entity\ServiceRequest::STATUS_REVIEW
* #uses \Entity\ServiceRequest::STATUS_PENDING
* #uses \Entity\ServiceRequest::STATUS_SCHEDULED
* #uses \Entity\ServiceRequest::STATUS_COMPLETE
*/
public function getStatus()
{
return $this->status;
}
/**
* #param int $status
*
* #uses \Entity\ServiceRequest::STATUS_REVIEW
* #uses \Entity\ServiceRequest::STATUS_PENDING
* #uses \Entity\ServiceRequest::STATUS_SCHEDULED
* #uses \Entity\ServiceRequest::STATUS_COMPLETE
*/
public function setStatus($status)
{
$this->status = $status;
}
/**
* #return \Entity\ServiceType
*/
public function getServiceType()
{
return $this->serviceType;
}
/**
* #return int
*/
public function isCanceled()
{
return $this->isCanceled;
}
public function getOrder()
{
return $this->order;
}
}
ServiceType Entity:
<?php
namespace Entity;
/**
* #Entity
* #Table(name="service_types")
*/
class ServiceType
{
/**
* #Id
* #Column(type="integer")
* #GeneratedValue
*
* #var int
*/
protected $id;
/**
* #Column(type="smallint")
*
* #var int
*/
protected $final;
/**
* #return int
*/
public function getId()
{
return $this->id;
}
/**
* #return int
*/
public function getFinal()
{
return $this->final;
}
}
You're querying servicetype before it is joined. Try:
SELECT o
FROM Entity\Order o
LEFT JOIN o.serviceRequests s
WITH s.status = :serviceStatus
LEFT JOIN s.serviceType t
WHERE o.status = :orderStatus
AND COUNT(s) = 0
AND t.final = 1
I have a member entity and a friend entity.
I get all the friends of a member by joining the tables.
I join the members on the friends via member_id.
TABLE STRUCTURE:
Members
member_id, full_name, email, password, date_joined
Friends
friendship_id, member_id, friend_id
Everything is fine but I can't get the full_name of the friend_id.
I ran the command line to generate the getters, setters, and join info in the entities.
In twig I get the friends array from the controller and calling friend.fullName returns my name, not my friends names but I joined on member_id that so thats fine.
I need to get the fullName of the member with the id of friend_id without 2 queries.
Ex.
member_id: 1, full_name:John
Friend
member_id: 22, full_name:Billy
I can call friend.friendId and it will return the 22, I'm stumped on getting the fullName
Member Entity
<?php
namespace Pixbelly\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
/**
* Pixbelly\AppBundle\Entity\Members
*
* #ORM\Table(name="members")
* #ORM\Entity(repositoryClass="Pixbelly\AppBundle\Repository\MembersRepository")
*/
class Members
{
/**
* #var integer $memberId
*
* #ORM\Column(name="member_id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $memberId;
/**
* #var string $fullName
*
* #ORM\Column(name="full_name", type="string", length=255, nullable=false)
*/
private $fullName;
/**
* #var string $email
*
* #ORM\Column(name="email", type="string", length=255, nullable=false)
*/
private $email;
/**
* #var string $password
*
* #ORM\Column(name="password", type="string", length=255, nullable=false)
*/
private $password;
/**
* #var \DateTime $dateJoined
*
* #ORM\Column(name="date_joined", type="datetime", nullable=false)
*/
private $dateJoined;
/**
* #ORM\OneToMany(targetEntity="Friends", mappedBy="member")
*/
protected $friends;
public function __construct()
{
$this->friends = new ArrayCollection();
}
/**
* Get memberId
*
* #return integer
*/
public function getMemberId()
{
return $this->memberId;
}
/**
* Set fullName
*
* #param string $fullName
* #return Members
*/
public function setFullName($fullName)
{
$this->fullName = $fullName;
return $this;
}
/**
* Get fullName
*
* #return string
*/
public function getFullName()
{
return $this->fullName;
}
/**
* Set email
*
* #param string $email
* #return Members
*/
public function setEmail($email)
{
$this->email = $email;
return $this;
}
/**
* Get email
*
* #return string
*/
public function getEmail()
{
return $this->email;
}
/**
* Set password
*
* #param string $password
* #return Members
*/
public function setPassword($password)
{
$this->password = $password;
return $this;
}
/**
* Get password
*
* #return string
*/
public function getPassword()
{
return $this->password;
}
/**
* Set dateJoined
*
* #param \DateTime $dateJoined
* #return Members
*/
public function setDateJoined($dateJoined)
{
$this->dateJoined = $dateJoined;
return $this;
}
/**
* Get dateJoined
*
* #return \DateTime
*/
public function getDateJoined()
{
return $this->dateJoined;
}
/**
* Add friends
*
* #param Pixbelly\AppBundle\Entity\Friends $friends
* #return Members
*/
public function addFriend(\Pixbelly\AppBundle\Entity\Friends $friends)
{
$this->friends[] = $friends;
return $this;
}
/**
* Remove friends
*
* #param Pixbelly\AppBundle\Entity\Friends $friends
*/
public function removeFriend(\Pixbelly\AppBundle\Entity\Friends $friends)
{
$this->friends->removeElement($friends);
}
/**
* Get friends
*
* #return Doctrine\Common\Collections\Collection
*/
public function getFriends()
{
return $this->friends;
}
}
Friends Entity
<?php
namespace Pixbelly\AppBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Pixbelly\AppBundle\Entity\Friends
*
* #ORM\Table(name="friends")
* #ORM\Entity(repositoryClass="Pixbelly\AppBundle\Repository\FriendsRepository")
*/
class Friends
{
/**
* #var integer $id
*
* #ORM\Column(name="friendship_id", type="integer", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $friendshipId;
/**
* #var integer $memberId
*
* #ORM\Column(name="member_id", type="integer", nullable=false)
*/
private $memberId;
/**
* #var integer $friendId
*
* #ORM\Column(name="friend_id", type="integer", nullable=false)
*/
private $friendId;
/**
* #ORM\ManyToOne(targetEntity="Members", inversedBy="friends")
* #ORM\JoinColumn(name="member_id", referencedColumnName="member_id")
*/
protected $member;
/**
* Get friendshipId
*
* #return integer
*/
public function getFriendshipId()
{
return $this->friendshipId;
}
/**
* Set memberId
*
* #param integer $memberId
* #return Friends
*/
public function setMemberId($memberId)
{
$this->memberId = $memberId;
return $this;
}
/**
* Get memberId
*
* #return integer
*/
public function getMemberId()
{
return $this->memberId;
}
/**
* Set friendId
*
* #param integer $friendId
* #return Friends
*/
public function setFriendId($friendId)
{
$this->friendId = $friendId;
return $this;
}
/**
* Get friendId
*
* #return integer
*/
public function getFriendId()
{
return $this->friendId;
}
/**
* Set member
*
* #param Pixbelly\AppBundle\Entity\Members $member
* #return Friends
*/
public function setMember(\Pixbelly\AppBundle\Entity\Members $member = null)
{
$this->member = $member;
return $this;
}
/**
* Get member
*
* #return Pixbelly\AppBundle\Entity\Members
*/
public function getMember()
{
return $this->member;
}
}