开发者

Custom columns in list view in Symfony admin generator

tl;dr: I need to show data from two different tables in the list view of the Symfony admin generator (preferably via a JOIN statement)

I'm using the sfDoctrineGuardPlugin to manage the users of my app. Each user also has their own profile that they can fill out. The schema (schema.开发者_运维问答yml) for the profile table looks like this:

sfGuardUserProfile:
  connection: doctrine
  tableName: sf_guard_user_profile
  columns:
    sf_guard_user_id: integer(8)
    client_id: string(128)
  relations:
    sfGuardUser:
      local: sf_guard_user_id
      foreign: id
      foreignType: one
      onDelete: CASCADE

Right now table is a client_id and a foreign key to the id column on the sfGuardUser table. (Yes, I know I need an id column in there just for DB accessibility, and more is coming later)

I've created an admin for my profile table using the Symfony admin generator. I would like my list view on the admin to look like this (generator.yml):

config:
  ...
  list:
    title:   Clients
    display: [client_id, sf_guard_user_id, username]
    table_method: retrieveProfileList

However, my username column does not work, and I receive a Doctrine_Record_UnkownPropertyException of:

Unknown record property / related component "username" on "sfGuardUserProfile"

I was hoping a custom table_method to populate the data for the list view would help me, but my table method (in lib/model/sfGuardUserProfileTable.class.php) does not seem to help. I followed an example in the Symfony Book, and this is the method:

public static function retrieveProfileList(Doctrine_Query $q)
{
  $rootAlias = $q->getRootAlias();

  $q->leftJoin($rootAlias . '.sfGuardUser id');

  return $q;
}

Any ideas on how to have the Symfony admin generator display a list view based on a join? Or, alternatively, how to pull from a separate model?


I have answered my own question!

I changed the join method on my sfGuardUserProfileTable class to something I could better understand (thanks to this helpful link):

public static function retrieveProfileList(Doctrine_Query $q)
{
  return $q->select('r.*, u.username')
          ->leftJoin('r.sfGuardUser u');
}

And threw in a getUsername method in my sfGuardUserProfile model class

  public function getUsername()
  {
      return $this->sfGuardUser->username;
  }

Thanks for being my rubber duck, SO!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜