Snippets

Create an account or login to be able to add, comment and rate snippets.

Navigation

Set relational id by name of record

This is a model function with a field named avatar_id, that links to the avatar table, id field, and allows you to set the id based on the name of the avatar.

static function getAvatarByName($name)
{
  $query = new Doctrine_Query();
  $query->select('a.id');
  $query->from('Avatar a');
  $query->where('name = ?', $name);
  $avatar = $query->execute();
 
  return $avatar[0];
}
 
public function setAvatarIdByName($name)
{
  $avatar = AvatarTable::getAvatarByName($name);
  $this->setAvatarId($avatar->getId());
}
by Jonathan Wage on 2007-04-05, tagged doctrine 
You need to create an account or log in to post a comment or rate this snippet.