开发者

Doctrine foreign keys

开发者 https://www.devze.com 2023-01-17 07:02 出处:网络
I get table - $data = Doctrine::getTable(\'product_catalog\')->findAll(); 开发者_开发问答 this table (product_catalog) i link table. has 2 columns with foreign keys.

I get table -

$data = Doctrine::getTable('product_catalog')->findAll();
开发者_开发问答

this table (product_catalog) i link table. has 2 columns with foreign keys.

how i can check if $data has a relation?


Try $data->hasRelation('RelationName') which will check for the existence of the related object on your foreign key. Replace RelationName with the real name of your relation.


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:

    $query = $this->entityManager->createQuery(YOUR_DQL_QUERY);
    $query->setHint(Query::HINT_INCLUDE_META_COLUMNS, true);
    $query->getArrayResult();
0

精彩评论

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