Skip to content

Instantly share code, notes, and snippets.

@patie
Created May 14, 2012 09:52
Show Gist options
  • Save patie/2693006 to your computer and use it in GitHub Desktop.
Save patie/2693006 to your computer and use it in GitHub Desktop.
<?php
/**
* Author: Patrik Gmitter <[email protected]>
* Date: 4/24/12
*/
namespace Eshop\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity
*/
class ProductAttribute extends \Nette\Object
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string")
*/
private $name;
public function getId()
{
return $this->id;
}
public function getName()
{
return $this->name;
}
public function setName($name)
{
$this->name = $name;
}
# V A L U E S
public function getValues()
{
return $this->values;
}
public function addValue(ProductAttributeValue $value)
{
$value->setAttribute($this);
$this->values[] = $value;
}
}
<?php
namespace Eshop\Model;
use Doctrine\Common\Collections\ArrayCollection;
/**
* @Entity(repositoryClass="Eshop\Model\ProductRepository")
*/
class Product extends \Nette\Object
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string")
*/
protected $name;
# next properties ...
/**
* UNI
*
* @ManyToMany(targetEntity="ProductAttributeValue")
* @JoinTable(name="Product_ProductAttributeValue",
* joinColumns={@JoinColumn(name="Product_id", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="ProductAttributeValue_id", referencedColumnName="id")}
* )
**/
protected $attributes;
# A T T R I B U T E S
public function getAttributes()
{
return $this->attributes;
}
public function addAttribute(ProductAttributeValue $attribute)
{
$this->attributes[] = $attribute;
}
}
<?php
/**
* Author: Patrik Gmitter <[email protected]>
* Date: 5/14/12
*/
namespace Eshop\Model;
/**
* @Entity
*/
class ProductAttributeValue extends \Nette\Object
{
/**
* @Id
* @Column(type="integer")
* @GeneratedValue
*/
private $id;
/**
* @Column(type="string")
*/
protected $value;
/**
* @ManyToOne(targetEntity="ProductAttribute", inversedBy="values")
* @JoinColumn(name="ProductAttribute_id", referencedColumnName="id")
**/
protected $attribute;
public function __construct(ProductAttribute $attribute, $value )
{
$this->attribute = $attribute;
$this->value = $value;
}
public function getId()
{
return $this->id;
}
public function getValue()
{
return $this->value;
}
public function setValue($value)
{
$this->value = $value;
}
# A T T R I B U T E
public function setAttribute(ProductAttribute $attribute)
{
$this->attribute = $attribute;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment