From 0f2499f93b0ea0d9afa57092fca16b198d13c05b Mon Sep 17 00:00:00 2001 From: piccoloprincipe Date: Thu, 2 Jul 2009 07:47:24 +0000 Subject: [PATCH] [2.0] added Collection object creation --- .../Tests/Models/ECommerce/ECommerceCart.php | 15 ++++++++++++++- .../Tests/Models/ECommerce/ECommerceCustomer.php | 5 ----- .../Tests/Models/ECommerce/ECommerceProduct.php | 15 +++++++++++---- 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php index 14457b699..fb1ef6a37 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php @@ -20,7 +20,7 @@ class ECommerceCart private $id; /** - * @Column(type="string", length=50) + * @Column(type="string", length=50, nullable=true) */ private $payment; @@ -37,6 +37,11 @@ class ECommerceCart inverseJoinColumns={{"name"="product_id", "referencedColumnName"="id"}}) */ private $products; + + public function __construct() + { + $this->products = new \Doctrine\Common\Collections\Collection; + } public function getId() { return $this->id; @@ -69,4 +74,12 @@ class ECommerceCart return $this->customer; } + public function getProducts() + { + return $this->products; + } + + public function addProduct(ECommerceProduct $product) { + $this->products[] = $product; + } } diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php index f393ab3a1..c5c8f19f1 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php @@ -41,11 +41,6 @@ class ECommerceCustomer $this->name = $name; } - /** - * @OneToMany(targetEntity="ECommerceProduct") - public $watched; - */ - public function setCart(ECommerceCart $cart) { if ($this->cart !== $cart) { diff --git a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php index ce6c6e122..a7e8e5031 100644 --- a/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php +++ b/tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php @@ -43,6 +43,11 @@ class ECommerceProduct private $categories; */ + public function __construct() + { + $this->features = new \Doctrine\Common\Collections\Collection; + } + public function getId() { return $this->id; @@ -89,10 +94,12 @@ class ECommerceProduct } public function removeFeature(ECommerceFeature $feature) { - $removed = $this->features->removeElement($feature); - if ($removed !== null) { - $removed->removeProduct(); - return true; + if ($this->features->contains($feature)) { + $removed = $this->features->removeElement($feature); + if ($removed) { + $feature->removeProduct(); + return true; + } } return false; }