[英]Doctrine foreign keys
I get table - 我得到了桌子 -
$data = Doctrine::getTable('product_catalog')->findAll();
this table (product_catalog) i link table. 这个表(product_catalog)我链接表。 has 2 columns with foreign keys.
有2列外键。
how i can check if $data
has a relation? 我如何检查
$data
是否有关系?
Try $data->hasRelation('RelationName')
which will check for the existence of the related object on your foreign key. 尝试
$data->hasRelation('RelationName')
,它将检查外键上是否存在相关对象。 Replace RelationName
with the real name of your relation. 将
RelationName
替换为您的关系的真实姓名。
I succeeded in getting relation from table: 我成功地从表中得到了关系:
$data = ORM::getTable($modelName)->findAll(); - get the table.
$relations = $data->getTable()->getRelations(); - >get to relation
foreach($relations as $key=>$row)
{
echo "<pre>"; var_dump($key); echo "</pre>";
}
die();
This will print the table relation on the screen. 这将在屏幕上打印表关系。
This solution works with Doctrine 2: 此解决方案适用于Doctrine 2:
$query = $this->entityManager->createQuery(YOUR_DQL_QUERY);
$query->setHint(Query::HINT_INCLUDE_META_COLUMNS, true);
$query->getArrayResult();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.