Reputation: 4210
I have this very simple method in my repository class which fetches a list as query builder object:
public function fetchListAsQueryBuilder(User $user, $receiverType, $limit, $offset)
{
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$query = $queryBuilder
->select(['no'])
->from('SLCoreBundle:Notification', 'no')
->where('no.receiver = :user')
->andWhere('no.receiverType = :receiverType')
->orderBy('no.createdAt', 'DESC')
->setParameters([
'user' => $user,
'receiverType' => $receiverType,
])
->setMaxResults($limit)
->setFirstResult($offset)
;
return $query;
}
this method works perfectly in my prod server, but gives an error in my local machine, php versions are same(5.5.9), here is an error:
An exception occurred while executing 'SELECT DISTINCT id_6 FROM (SELECT s0_.receiver_type AS receiver_type_0, s0_.importance AS importance_1, s0_.seen AS seen_2, s0_.deleted AS deleted_3, s0_.created_at AS created_at_4, s0_.updated_at AS updated_at_5, s0_.id AS id_6, s0_.reason AS reason_7 FROM sl_notification s0_ WHERE s0_.receiver_id = ? AND s0_.receiver_type = ?) dctrn_result ORDER BY s0_.created_at DESC LIMIT 25 OFFSET 0' with params [2, 1]:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 's0_.created_at' in 'order clause'
My entity has been configured like this:
Mapped superclass AbstractMessage:
abstract class AbstractMessage
{
use CreatedUpdatedAtTrait;
// here go properties, setters and getter
Notification class:
class Notification extends AbstractMessage
{
// here go properties, setters and getters
And CreateUpdatedAtTrait:
trait CreatedUpdatedAtTrait
{
/**
* @var \DateTime
*/
private $createdAt;
/**
* @var \DateTime
*/
private $updatedAt;
// Here go setters and getters
}
Schema (AbstractMessage) :
<mapped-superclass name="SL\CoreBundle\Entity\AbstractMessage">
...
<field name="createdAt" column="created_at" type="datetime">
<gedmo:timestampable on="create" />
</field>
<field name="updatedAt" column="updated_at" type="datetime">
<gedmo:timestampable on="update" />
</field>
</mapped-superclass>
here is the db table:
I'dont understand what causes this error, my others entities work well with this trait, and also my other queries with orderBy
method and mappedsuperclass classes work without any error. And also very interesting part is if I remove orderBy
my method is working and I am able to get the createdAt
value ($object->getCreatedAt()
). Can anyone help me to solve this problem?
Edit: I forgot to mention, that I've recently updated vendors to the latest versions(sf-2.6.6, DoctrineORM-2.5.0).
Upvotes: 2
Views: 809
Reputation: 31
I think it's cause by doctrine 2.5 +
So i switched back to 2.4.7 and its working again !
In my composer.json
"require": {
...
"doctrine/orm": "2.4.7",
...
}
And update
php composer.phar update
Upvotes: 3