views:

725

answers:

2

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?

A: 

Remove table names from schema:

...
A: { onDelete: CASCADE, local: id, foreign: id, foreignalias: AB }
...
Darmen
darmen, its a mistake writing it. in my schema definition i don't have a. and b.thanks
nebur85
+2  A: 

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:

A:
  relations:
    B:
      local: id
      foreign: id
      foreignAlias: AB
      foreignType: many
      type: one

See also http://www.doctrine-project.org/documentation/manual/1_0/ru/yaml-schema-files#relationships:one-to-many for detect_relations option.

Vladimir
i don't understand what is differerent in my one to may definition and the one-to-many in the web you write..
nebur85