i have a product entity that extends from base entity. product entity doesn't have a "created_at" field (attribute - variable) but base entity has, so product table in MySQL has a column named created_at (because it extends from base entity class). in doctrine orm, query builder mapped from product entity and doesn't recognize "created_at" field. i want to get products ordered by "created_at" but it gives me an error that the field "created_at" is not defined in product entity. is there any solution to set orderBy function based on column name and not on entity?
my function:
$queryBuilder->addOrderBy('product.created_at', 'ASC');
error:
[Semantical Error] line 0, col 86 near 'created_at A': Error: Class App\\Entity\\Product has no field or association named created_at
product table schema:
CodePudding user response:
well, i found my mistake. change clause to :
$queryBuilder->addOrderBy('product.createdAt', 'ASC');
column's name is created_at but the field is createdAt (strange!!!) by the way here is my product entity and base entity (just for better understanding):