Oct 26 2009

Alphabetizing Many-to-many Relationships in the Admin Generator

Category: Admin GeneratorJeff @ 4:39 pm
      

I searched high and low for a solution that I could place in my generator.yml file in order to alphabetize (or somehow order) the associated attributes for a given piece of data.  I was certain I’d be able to do this using a params configuration.  Finally, I realized it’s not going to be solved by editing the generator file.  So instead I opened the model file that I used in the generator file and overrode the doSelect method like this:

public static function doSelect(Criteria $criteria, PropelPDO $con = null)
	{
		if(count($criteria->getOrderByColumns()) == 0)
		{
				$criteria->addAscendingOrderByColumn(self::NAME);
		} 

		return self::populateObjects(self::doSelectStmt($criteria, $con));
	}

Of course, I’m using Propel… and I have a “name” column that I wanted to alphabetize on. But you get the point. Edit the above as you see fit for your needs.

Leave a Reply