Details
Description
I find no way to define automatic orderBy in m2m relations with column not from reference table, but actual related table.
E.g. BlogPost <= m2m through BlogPostCategory => BlogCategory
I need BlogPost->Categories ordered by BlogCategory.name
class BlogPost extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('title', 'string', 128); $this->hasColumn('content', 'string'); } public function setUp() { $this->hasMany('BlogCategory as BlogCategories', array('local' => 'id_blog_post', 'foreign' => 'id_blog_category', 'refClass' => 'BlogPostCategory', 'orderBy' => 'name')); } } class BlogCategory extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('name', 'string', 128); } public function setUp() { $this->hasMany('BlogPost as BlogPosts', array('local' => 'id_blog_category', 'foreign' => 'id_blog_post', 'refClass' => 'BlogPostCategory')); } } class BlogPostCategory extends Doctrine_Record { public function setTableDefinition() { $this->hasColumn('id_blog_post', 'integer', null, array('primary' => true)); $this->hasColumn('id_blog_category', 'integer', null, array('primary' => true)); } public function setUp() { $this->hasOne('BlogPost', array('local' => 'id_blog_post', 'foreign' => 'id', 'onDelete' => 'CASCADE')); $this->hasOne('BlogCategory', array('local' => 'id_blog_category', 'foreign' => 'id', 'onDelete' => 'CASCADE')); } }
The resulting query contains doubled 'name' column in ORDER BY clause, both from reference table and related table, e.g. ORDER BY t2.name, t3.name
I tried putting the following code in BlogCategory::setTableDefinition() instead of attribute in relation definition in BlogPost record:
$this->option('orderBy', 'name');
but the result was the same.
Maybe I'm doing something wrong? Is there a possibility to define an alias, where to get column name from - in orderBy attribute?
Thanks in advance.
Activity
Maciej Hołyszko
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Attachment | DC313TestCase.php [ 10202 ] |
Maciej Hołyszko
made changes -
| Priority | Major [ 3 ] | Blocker [ 1 ] |
This list may be incomplete, as errors occurred whilst retrieving source from linked applications:
- Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DC-313, expand=changesets[-21:-1].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)
Attached test case.