Have been looking for way to sort foreign key records in Symfony 1.4 for few days. I’ve a staff table with a foreign key to comments. Whenever i call the StaffTable->getComments() the records return is not in alphabetical order. Finally i found some helpful tips from a forum (sorry i lost the forum url), and i manage to sort foreign key record with just a line of code. 🙂
To sort foreign key record in Symfony 1.4, follow the steps below:-
Advertisements
- Open the file lib/model/doctrine/base/BaseStaff.class.php and look for the function name ‘setUp‘ and look for this:-
$this->hasMany('Comment', array( 'local' => 'staff_id', 'foreign' => 'comment_id', 'onDelete' => 'setnull'));
Copy it and follow the next step.
- go to lib/model/doctrine/Staff.class.php
- Create a function as below:-
public function setUp() { parent::setUp(); $this->hasMany('Comment', array( 'local' => 'staff_id', 'foreign' => 'comment_id', 'orderBy' => 'created_at', 'onDelete' => 'setnull'));)); }
- Now refresh the page and you should see your record being sorted according to created_at time
Related posts:
How to install SVN 1.6 on CentOS 5
WordPress Dev: How to send html email using wp_mail()?
Free Project Management software for Mac OS X - GanttProject
How to create mailing list in Thunderbird
Symfony: Control Model->save() function to perform INSERT or UPDATE
Composer: PHP Fatal error: Allowed memory size of ... exhausted...
Symfony: PHP Fatal error: Call to a member function setData()
MySQL 5.5 PDO::__construct(): The server requested authentication method unknown to the client [mysq...
Share this with your friends:-