2
votes

http://www.symfony-project.org/jobeet/1_4/Doctrine/en/12

The section "Virtual" columns details how to add columns to lists that belong to related models.

For example, I have 2 model classes: Company and User. A User is always a member of a Company.

For the User list I want to show the Company name, I can do this by adding a getter to the User class getCompanyName() and then in my generator.yml for the User module I would use the field name company_name.

This works and displays the Company name for each User, but how can I sort the list by using the Company name?

1
Do you have the relationship properly set in your schema.yml? Because if you do by building filters it would automatically add this field.Pabloks
My User has a one-to-one relationship set, my Company does not have a User relation. I can call $user->getCompany() but would never need to call $company->getUser() (this would need to be multiple users anyway) I would like to filter by Company as well as sorting by company. In the documentation there is a function called addSortCriteria() but I think this has to be used with Propel and not Doctrinejasper11
Try to add the relationship beetween Company and User. I think that will tell symfony to add that filter in user. I'm always defining both relationships and, by now, it never failed.Pabloks
But even if I add that, the sorting still won't work. The admin generated actions class checks that the sort field is valid column for the User table, and of course company_name is no column. I can add a CompanyName getter like I said above, but not sure how to tie it all together. I really need to be able to sort the Users list by their Company, and filter by Company toojasper11
I got it working, but it shows me the company id, and I can sort by that... but is there anyway I can use the __toString method so it shows the company name instead of the id?jasper11

1 Answers

0
votes

I solve this by adding a table_method, then when I implement the table method in the model, I innerjoin Company and order by a field in company. Not sure if this can be extended to sorting columns in the generated screens, but I think this works as well.