This is my problem:
If you can, provide a general answer and then a specific answer for symfony 1.4 and doctrine. That would be useful for more people and for myself who works in multiple frameworks.
I need this to handle permissions on the CRUD of some tables.
I find that this is a very recurrent problem
Maybe there is a pattern or a plugin that solves this problem?
Currently i just came up with this:
$someRow = Doctrine_Query::create()->from('SomeTable')->
where('id = ?', $id_someTable)->
andWhere('id_relation = ?',$id_someOtherTable)->execute();
return $someRow->count() > 0;
For some reason i find this ugly...
Your title is more explicit than your text, anyway.
You have a function called getRelations
in Table.php. So you can retrieve all relations to an object and then, make what ever you want with the result.
/**
* Retrieves all relation objects defined on this table.
*
* @return array
*/
public function getRelations()
{
return $this->_parser->getRelations();
}
So :
$relations = Doctrine_Core::getTable('SomeTable')->getRelations();
For more detail, here is the parser getRelations method.
Edit:
And if you want to try for a given relation, you can then use hasRelation
.