Elad Kaplan
Elad Kaplan

Reputation: 33

Doctrine 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?

Upvotes: 1

Views: 1086

Answers (3)

db80
db80

Reputation: 4427

This solution works with Doctrine 2:

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

Upvotes: 0

Elad Kaplan
Elad Kaplan

Reputation: 33

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.

Upvotes: 2

PeterB
PeterB

Reputation: 2330

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.

Upvotes: 2

Related Questions