CREATE TABLE Product ( id INT AUTO_INCREMENT NOT NULL, shipping_id INT DEFAULT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; CREATE TABLE Shipping ( id INT AUTO_INCREMENT NOT NULL, PRIMARY KEY(id) ) ENGINE = InnoDB; ALTER TABLE Product ADD FOREIGN KEY (shipping_id) REFERENCES Shipping(id);
Chciałbym wykonać takie zaspytanie:
SELECT * FROM shipping JOIN product ON product.shipping_id = shipping.id
Stowrzylem takie klasy:
Model Product.php
<?php namespace models; /** * @Entity * @Table(name="product") */ class Product{ /** * @Id * @Column(name = "`id`", type="integer", nullable=false, unique=true ) * @GeneratedValue(strategy="AUTO") */ private $id; /** * @Column(name = "`shipping_id`") * @OneToOne(targetEntity="Shipping") * @JoinColumn(name="shipping_id", referencedColumnName="id") **/ private $shipping; }
model Shipping.php
<?php namespace models; /** * @Entity * @Table(name="shipping") */ class Shipping { /** * @Id * @Column(name="id", type="integer", nullable=false) * @GeneratedValue(strategy="AUTO") */ private $id; }
kontroler
$em = $this->doctrine->em; $query = $em->createQueryBuilder() ->select('u') ->from('models\Shipping', 'u') //->leftJoin('u.id', 'a') ->getQuery(); $results = $query->getResult();
Dostaja bląd który nic mi nie mówi
Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Semantical Error] line 0, col 52 near 'a': Error: Class models\Shipping has no association named Product' in C:\wamp\www\ideaWeb_CMS_doctrine\app\libraries\Doctrine\ORM\Query\QueryException.php on line 47
Jak powinno to wygladać w prawidłowy sposób ?