I have two tables A and B. A have one or more registers in B.
I want to join two tables and extract all information about A.
I do that:
Schema.yml
A:
fields.....
B:
fields...
relations:
A: { onDelete: CASCADE, local: a.id, foreign: b.id, foreignalias: AB }
And i try to do that…
$q = Doctrine_Query::create()
->from('A a')
->leftJoin('a.AB b')
->where('a.field = "D"')
->andWhere('b.codzon = ?', $this->cp);
It prints me error: Unknown relation alias AB
What i am doing wrong?
Your query seems to be ok, errors are in you sheme definition. You need to define relations on both sides: A and B. I am not very comfortable with YML, but it should look like this:
See also http://www.doctrine-project.org/documentation/manual/1_0/ru/yaml-schema-files#relationships:one-to-many for detect_relations option.