This topic contains 10 replies, has 3 voices, and was last updated by Benjamin 6 years, 6 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- September 26, 2017 at 8:55 am #30744
Hello guys,
I need to display a custom entity datagrid in the customer datagrid.
I used the query_builders parameters in datagrid configuration
YAML1234567891011121314customer-reward-point-grid:source:type: ormquery_builder: '@reward_point.customer_reward_point.repository->findByCustomerId'bind_parameters:- customer_idcolumns:type:label: Typerate:label: Ratefrontend_type: numberdescription:label: DescriptionI tried to link a request parameter to it (Id of current customer) to pass it to the request but when I dump this parameter in the query I obtain the code of the datagrid(customer-reward-point-grid) and not the value of my request:
PHP12345678910111213141516/*** @param $customerId** @return \Doctrine\ORM\QueryBuilder*/public function findByCustomerId($customerId){$queryBuilder = $this->createQueryBuilder('crp')->select('crp.earnedPoints, crp.spentPoints, rp.type, rp.rate, rp.description')->where('c.id = :customer_id')->join('crp.customer', 'c')->join('crp.rewardPoint', 'rp')->setParameter('customer_id', $customerId);dump($customerId);return $queryBuilder;}Can someone help me?
Thanks and have a nice day!
- CreatorTopic
- AuthorReplies
- September 26, 2017 at 9:07 am #30745
I solve it: no need to specify the condition and the parameter in the query when using bind_parameters.
PHP123456789101112/*** @return \Doctrine\ORM\QueryBuilder*/public function findByCustomerId(){$queryBuilder = $this->createQueryBuilder('crp')->select('crp.earnedPoints, crp.spentPoints, rp.type, rp.rate, rp.description')->join('crp.customer', 'c')->join('crp.rewardPoint', 'rp');return $queryBuilder;}But now I have another error:
Getting grid data failed.
Context: { “exception”: “Exception(Doctrine\\ORM\\Query\\QueryException): [Semantical Error] line 0, col 11 near ‘customer, crp.rewardPoint’: Error: Invalid PathExpression. Must be a StateFieldPathExpression.” }Anyone have an idea? I already had this error when using the query from the datagrid.yml (without the query_builders parameter).
September 26, 2017 at 9:27 am #30746Hi! Are you sure its valid name customer_id maybe when you rendering grid you use another name? For example try to use like:
PHP12bind_parameters:customerId: customer_idMore information about parameter binding you can read in https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/DataGridBundle/Resources/doc/backend/parameter_binding.md
September 26, 2017 at 9:31 am #30747Hello dzakharov and thanks for the fast reply!
I solved my parameter binding issue in my first post but now I have the error raised in my second post I don’t think it is related to the first one.
September 26, 2017 at 9:43 am #30748Also if you want to use datagrids without query_builders, you can try write like:
PHP12345678910111213141516customer-reward-point-grid:source:type: ormquery:select: [crp.earnedPoints, crp.spentPoints, rp.type, rp.rate, rp.description]from:- { table: YoursBundle:Entity, alias: crp }join:inner:- { join: crp.customer, alias: c }- { join: crp.rewardPoint, alias: rp }where:and:- c.id = :customer_idbind_parameters:- customer_idDocumentation with examples how use datagrids: https://github.com/oroinc/platform/blob/master/src/Oro/Bundle/DataGridBundle/Resources/doc/backend/datagrid.md
September 27, 2017 at 12:27 am #30749Hello dzakharov,
I read the data grids doc, at my first attempt I even applied the method in your last comment with datagrid without query_builders. I obtained exactly the same result as the error in my second post :
Getting grid data failed.
Context: { “exception”: “Exception(Doctrine\\ORM\\Query\\QueryException): [Semantical Error] line 0, col 11 near ‘customer, crp.rewardPoint’: Error: Invalid PathExpression. Must be a StateFieldPathExpression.” }So I tried to build my grid with the query_builders parameters…but now I have this error too with this configuration and I don’t know how to solve it.
Thanks for your reply,
Regards
October 3, 2017 at 9:18 pm #30750Hello Benjamin,
Are you able to provide full example that causing this error for you (so all Entities, current Repository and current grid configuration)?
Regards
JakubOctober 4, 2017 at 12:40 am #30751Hello jderziak,
Thanks for your reply.
Here it is:RewardPoint Entity:
PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136/*** @ORM\Entity()* @ORM\Table(name="reward_point")** Class RewardPoint*/class RewardPoint{/*** @ORM\Id()* @ORM\GeneratedValue(strategy="AUTO")* @ORM\Column(type="integer")** @var integer $id*/private $id;/*** @ORM\Column(type="float")** @var float $rate*/private $rate;/*** @ORM\Column(type="string")** @var string $type*/private $type;/*** @ORM\Column(type="text")** @var string $description*/private $description;/*** @ORM\Column(type="datetime", name="start_date", nullable=true)** @var \DateTime $startDate*/private $startDate;/*** @ORM\Column(type="datetime", name="end_date", nullable=true)** @var \DateTime $endDate*/private $endDate;/*** @return int*/public function getId(){return $this->id;}/*** @return float*/public function getRate(){return $this->rate;}/*** @param float $rate*/public function setRate($rate){$this->rate = $rate;}/*** @return string*/public function getType(){return $this->type;}/*** @param string $type*/public function setType($type){$this->type = $type;}/*** @return string*/public function getDescription(){return $this->description;}/*** @param string $description*/public function setDescription($description){$this->description = $description;}/*** @return \DateTime*/public function getStartDate(){return $this->startDate;}/*** @param \DateTime $startDate*/public function setStartDate($startDate){$this->startDate = $startDate;}/*** @return \DateTime*/public function getEndDate(){return $this->endDate;}/*** @param \DateTime $endDate*/public function setEndDate($endDate){$this->endDate = $endDate;}}RewardPointCustomer Entity:
PHP123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102/*** @ORM\Entity(repositoryClass="Acme\Bundle\RewardPointsBundle\Repository\CustomerRewardPointRepository")* @ORM\Table(name="reward_point_customer")** Class RewardPointCustomer*/class RewardPointCustomer{/*** @var integer $customer** @ORM\Id()* @ORM\ManyToOne(targetEntity="Oro\Bundle\CustomerBundle\Entity\Customer")*/private $customer;/*** @var integer $rewardPoint** @ORM\Id()* @ORM\ManyToOne(targetEntity="Acme\Bundle\RewardPointsBundle\Entity\RewardPoint")*/private $rewardPoint;/*** @ORM\Column(type="integer", name="earned_points", nullable=true)** @var integer $earnedPoints*/private $earnedPoints;/*** @ORM\Column(type="integer", name="spent_points", nullable=true)** @var integer $spentPoints*/private $spentPoints;/*** @return int*/public function getCustomer(){return $this->customer;}/*** @param int $customer*/public function setCustomer($customer){$this->customer = $customer;}/*** @return int*/public function getRewardPoint(){return $this->rewardPoint;}/*** @param int $rewardPoint*/public function setRewardPoint($rewardPoint){$this->rewardPoint = $rewardPoint;}/*** @return mixed*/public function getEarnedPoints(){return $this->earnedPoints;}/*** @param mixed $earnedPoints*/public function setEarnedPoints($earnedPoints){$this->earnedPoints = $earnedPoints;}/*** @return int*/public function getSpentPoints(){return $this->spentPoints;}/*** @param int $spentPoints*/public function setSpentPoints($spentPoints){$this->spentPoints = $spentPoints;}}Datagrid:
YAML1234567891011121314customer-reward-point-grid:source:type: ormquery_builder: '@reward_point.customer_reward_point.repository->findByCustomerId'bind_parameters:- customer_idcolumns:type:label: Typerate:label: Ratefrontend_type: numberdescription:label: DescriptionCustomerRewardPointRepository used:
PHP123456789101112/*** @return \Doctrine\ORM\QueryBuilder*/public function findByCustomerId(){$queryBuilder = $this->createQueryBuilder('crp')->select('crp.earnedPoints, crp.spentPoints, rp.type, rp.rate, rp.description')->join('crp.customer', 'c')->join('crp.rewardPoint', 'rp');return $queryBuilder;}I suspect a misconfiguration in my entity in the relation with oro customer entity.
Again thanks for taking your time for this!
October 4, 2017 at 3:40 am #30752Hello Benjamin,
Looks like your entity primary key is causing error:
PHP1234567891011121314/*** @var integer $customer** @ORM\Id()* @ORM\ManyToOne(targetEntity="Oro\Bundle\CustomerBundle\Entity\Customer")*/private $customer;/*** @var integer $rewardPoint** @ORM\Id()* @ORM\ManyToOne(targetEntity="Acme\Bundle\RewardPointsBundle\Entity\RewardPoint")*/private $rewardPoint;As a walkaround you may remove this primary key (use UNIQUE instead) and create normal “id” field.
PHP1234567891011121314151617181920212223/*** @ORM\Id()* @ORM\GeneratedValue(strategy="AUTO")* @ORM\Column(type="integer")** @var integer $id*/private $id;/*** @var \Oro\Bundle\CustomerBundle\Entity\Customer $customer** @ORM\ManyToOne(targetEntity="Oro\Bundle\CustomerBundle\Entity\Customer")* @ORM\JoinColumn(name="customer_id", referencedColumnName="id", onDelete="CASCADE")*/private $customer;/*** @var \AcmeBundle\Entity\RewardPoint $rewardPoint** @ORM\ManyToOne(targetEntity="AcmeBundle\Entity\RewardPoint")* @ORM\JoinColumn(name="rewardPoint_id", referencedColumnName="id", onDelete="CASCADE")*/private $rewardPoint;In the meantime I’ll try to find out if it’s a correct behavior.
October 4, 2017 at 9:06 pm #30753Hello again!
I’ve confirmed this is a bug, but since it’s not recommended to create Primary Key from reference columns, it has quite low priority and I’m not able to predict how fast the fix will be implemented.
Regards
JakubOctober 4, 2017 at 11:58 pm #30754Hello jderdziak!
Thanks for your help!
I will create a normal Id field then!
I will open an issue but I agree with you it should be a low priority since it’s not the best practice to do it.Have a great week!
Regards
- AuthorReplies
The forum ‘OroCRM’ is closed to new topics and replies.