Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doctrine 2, joining with other table and issue with sort-able field. #89

Open
utterly-calm opened this issue Dec 20, 2015 · 0 comments
Open

Comments

@utterly-calm
Copy link

$qb->select("s","u")
      ->add('from', 'Application\Entity\Schools s')
      ->leftJoin('s.user', 'u', 'WITH', 'u.id = s.user');

protected $headers = array(
    'id' =>     array('tableAlias' => 's', 'title' => 'Id', 'width' => '50', 'sortable' => false) ,
        'name' =>   array('tableAlias' => 's', 'title' => 'Name' , 'filters' => 'text') ,
        'user' =>   array('tableAlias' => 'u', 'title' => 'Entered By' , 'filters' => 'text') ,
        'createdAt' =>   array('tableAlias' => 's', 'title' => 'Created At' , 'filters' => 'text') ,
        'modifiedAt' =>   array('tableAlias' => 's', 'title' => 'Modified At' , 'filters' => 'text') ,
        'status' =>   array('tableAlias' => 's', 'title' => 'Status','filters' => array( null => 'All' , 1 => 'Active' , 0 => 'Inactive')) ,
);
public function init()
{
       $this->getHeader('user')->getCell()->addDecorator('callable', array(
            'callable' => function($context, $record){
                if(is_object($record->getUser())){
                    return $record->getUser()->getFirstname().' '.$record->getUser()->getLastname();
                }else{
                    return '-';
                }
            }
        ));
}

Users Entity:
/**
* @ORM\OneToMany(targetEntity="Application\Entity\Schools", mappedBy="user")
*/
private $school;

Schools Entity:
/**
 * @var \Application\Entity\Users
 *
 * @ORM\ManyToOne(targetEntity="Application\Entity\Users", inversedBy="school")
 * @ORM\JoinColumns({
    *   @ORM\JoinColumn(name="user_id", referencedColumnName="id")
 * })
 */
 private $user;

Everythings working fine including proper listing, individual search on each column, pagination and so on. But when sorted by "Entered By" (user) column, it displays following error:

[Semantical Error] line 0, col 95 near 'user asc': Error: Class Application\Entity\Users has no field or association named user

I understand that why this error is happening but how to resolve it. How to customize sort-able columns. I think there must be way to resolve it using doctrine 2 query builder or the other way could be to modify it inside zftable methods. I'm not sure how to resolve it.

Thanks for any help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant