Temat: ZF + DOCTRINE - broblem leftjoin

Witam mam problem, żeby połączyć dwie tabele
schema.yml

Customers:
columns:
id:
primary: true
autoincrement: true
type: integer(4)
user_id:
type: integer(4)
types:
type: string(30)
name:
type: string(40)
surname:
options:
collate: utf8_general_ci
charset: utf8


Adress:
columns:
id:
primary: true
autoincrement: true
type: integer(4)
customers_id:
type: integer(4)
street:
type: string(20)
email:
type: string(25)
relations:
Customers:
foreignAlias: adresss
onDelete: cascade
onUpdate: cascade
options:
collate: utf8_general_ci
charset: utf8

leftjoin wygląda tak :

contact2 = Doctrine_Query::create()
->from('customers u')
->leftjoin('u.adresss a')
->execute();

calosc przekazuje do widoku:

$this->view->contacts = $contact2->toarray();

a w widoku

foreach($this->contacts as $index => $contact):

i $contact['email'] i w tym miejscu wskauje blad Notice: Undefined index: email in C:\wamp\www\zends\application\views\scripts\contacts\index.phtml on line 39
Wyświetlane są dane tylko z tabeli Customers. Może ktoś pomoc?
pozdrawiamMarek Perończyk edytował(a) ten post dnia 29.09.10 o godzinie 14:34

Temat: ZF + DOCTRINE - broblem leftjoin

byś to chociaz sformatowane wrzucił ;p

Adress:
connection: dbCrm
tableName: adress
columns:
id:
type: integer(4)
customers_id:
type: integer(4)
relations:
Customers:
local: customers_id
foreign: id
type: one
class: Customers

typ relacji definiujesz z obu stron
albo jest type: one albo type: many

Doctrine_Query::create()
->from('Adress a')
->leftjoin('a.Customers c')
->execute();

Temat: ZF + DOCTRINE - broblem leftjoin

zrobilem tak jak psales nie wiem czy dobrze:

Customers:

tableName: customers
columns:
id:
primary: true
autoincrement: true
type: integer(4)
user_id:
type: integer(4)
types:
type: string(30)
name:
type: string(40)

relations:
Adress:
local: id
type: many
class: Adress
options:
collate: utf8_general_ci
charset: utf8


Adress:

tableName: adress
columns:
id:
primary: true
autoincrement: true
type: integer(4)
customers_id:
type: integer(4)
street:
type: string(20)

relations:
Customers:
local: customers_id
foreign: id
type: one
class: Customers
foreignAlias: Adresss
onDelete: cascade
onUpdate: cascade
options:
collate: utf8_general_ci
charset: utf8


$contact2 = Doctrine_Query::create()
->from('Adress c')
->leftjoin('c.Customers a') ->execute();
$this->view->contacts = $contact2->toarray();

Tera sa dane tylko z tabeli Adress. ;(
Dobrze robie dajac wszystko do tablicy?? Toarray();Marek Perończyk edytował(a) ten post dnia 30.09.10 o godzinie 00:10
Łukasz C.

Łukasz C. Senior Technical
Architect

Temat: ZF + DOCTRINE - broblem leftjoin

1: toArray smierdzi! dodaj do query: $query->setHydrationMode(Doctrine::HYDRATE_ARRAY);

2: doctrine ma problem z leftjoinem przy myisam, sprawdz czy napewno twoje tabelki to napewno innodb

Temat: ZF + DOCTRINE - broblem leftjoin

W phpmyadmin jest typ innodb


$query = Doctrine_Query::create()
->from('Adress cus')
->leftjoin('cus.Customers a')
->setHydrationMode(Doctrine::HYDRATE_ARRAY);

$contact= $query->execute();
$this->view->contacts = $contact;

Taka proba tez bez efektow dalej jedna tabela ktos jeszcze jakies pomysly?
Maciej Niedźwiecki

Maciej Niedźwiecki Born to rails hell

Temat: ZF + DOCTRINE - broblem leftjoin

A próbowałeś podać do zapytania pola? Bo powinien ten left join zadziałać bez problemu, ale pamiętam, że kiedyś miałem problemy jak nie wskazałem pola 'id' z jednej tabeli.

...
->select(cus.*, a.*)
...
Arkadiusz Burszczan

Arkadiusz Burszczan Programista Java

Temat: ZF + DOCTRINE - broblem leftjoin

Ja korzystam z metody _init w boostrapie

protected function _initDoctrine()
{
$this->getApplication()->getAutoloader()->pushAutoloader(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
$manager->setAttribute(Doctrine::ATTR_MODEL_LOADING, Doctrine::ATTR_LOAD_REFERENCES);
$manager->setAttribute(Doctrine::ATTR_AUTOLOAD_TABLE_CLASSES, true);
$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$doctrineConfig = $this->getOption('doctrine');
Doctrine::loadModels($doctrineConfig['models_path'], Doctrine::MODEL_LOADING_CONSERVATIVE);
$conn = Doctrine_Manager::connection($doctrineConfig['dsn'], 'doctrine');

// Doctrine_Core::generateModelsFromDb(APPLICATION_PATH.'/models', array('doctrine'), array('generateTableClasses' => true));
$conn->setAttribute(Doctrine::ATTR_USE_NATIVE_ENUM, true);

return $conn;
}

Odkomentowuje sobie tylko linijkę Doctrine::Core, jeśli wprowadziłem jakieś zmiany w bazie, odświeżam stronę i wtedy Doctrine sam generuje sobie modele, warunek jeden, że baza musi być w INNODB i poustawiane klucze obce. Normalnie ta linijka jest zakomentowana cały czas.Arkadiusz Burszczan edytował(a) ten post dnia 15.10.10 o godzinie 22:48

Następna dyskusja:

Zend + Doctrine




Wyślij zaproszenie do