Hi folks,

Awhile ago i wrote a wiki article and a plugin covering how to get the
admin generator's list view to sort alphabetically when the field
you're sorting on is a foreign key.

For instance, if you have a table of events and a table of DJs and
events reference DJs through a foreign key field, dj_id, and you click
on the top of the DJ column, you probably want to see events sorted
alphabetically by DJ name, not DJ id. Natively Symfony has no support
for this (not in 1.0 and, as far as I can tell, not in 1.2 either). I
wrote a plugin for that some time back,
sfAdminSortByForeignNamePlugin. At the time I assumed that the plugin
probably wouldn't be necessary in Symfony 1.2 but as far as I've been
able to infer from the code so far, it is probably still necessary.

More recently I've noticed that this problem also comes up with
filters. If you add dj_id to your list of filtered columns, the DJs in
the pulldown menu for the filter will be in order by ID, not
alphabetically. There is no documentation covering how to fix this,
but it turns out that Symfony does support it via generator.yml.

I've just updated my article on sorting by foreign keys to cover the
filter issue as well. As it turns out you can specify a peer method to
be used to fetch the array of DJs. You configure this like so, in both
Symfony 1.0 and 1.2 (note that according to the source this appears to
still be the case in 1.2 even though 1.2 also has a filter: key in
generator.yml):

   fields:
        dj_id:
          params:
            peer_method: getAll

This causes the admin generator to invoke DjPeer::getAll() instead of
Dj::doSelect(), which is the default.

You can find the updated article here:

http://trac.symfony-project.org/wiki/HowtoSortAdminGeneratorListByForeignTableName

Hope you find it helpful!

-- 
Tom Boutell

www.punkave.com
www.boutell.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"symfony users" group.
To post to this group, send email to symfony-users@googlegroups.com
To unsubscribe from this group, send email to 
symfony-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/symfony-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to