Skip to content

Commit

Permalink
ORM Relations
Browse files Browse the repository at this point in the history
  • Loading branch information
terwey committed Apr 28, 2014
1 parent 27c0e2e commit ffb8653
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
3 changes: 3 additions & 0 deletions newscoop/application/configs/symfony/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ jms_serializer:
Newscoop_Image:
namespace_prefix: Newscoop\Image
path: "@NewscoopGimmeBundle/Resources/config/serializer/newscoop"
Newscoop_Snippet:
namespace_prefix: Newscoop\Entity\Snippet
path: "@NewscoopGimmeBundle/Resources/config/serializer/newscoop"


# SensioExtraBundle Configuration
Expand Down
6 changes: 3 additions & 3 deletions newscoop/library/Newscoop/Entity/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,8 @@ class Snippet
protected $name;

/**
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Snippet\SnippetField", mappedBy="snippet", cascade={"persist"})
* @ORM\JoinColumn(name="FieldId", referencedColumnName="Id")
* @var Newscoop\Entity\Snippet\SnippetField
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Snippet\SnippetField", mappedBy="snippet", cascade={"persist", "remove"})
* @var Doctrine\Common\Collections\ArrayCollection
*/
protected $fields;

Expand Down Expand Up @@ -117,6 +116,7 @@ public function setTemplate(SnippetTemplate $template)

foreach ($template->getFields() as $templateField) {
$field = new SnippetField();
$field->setSnippet($this);
$field->setTemplateField($templateField);
$this->addField($field);
}
Expand Down
30 changes: 28 additions & 2 deletions newscoop/library/Newscoop/Entity/Snippet/SnippetField.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ class SnippetField

/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Snippet", inversedBy="fields")
* @ORM\JoinColumn(name="SnippetId", referencedColumnName="Id")
* @ORM\JoinColumn(name="SnippetId", referencedColumnName="Id", nullable=false)
* @var Newscoop\Entity\Snippet
*/
protected $snippet;

/**
* @ORM\OneToOne(targetEntity="Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField")
* @ORM\JoinColumn(name="TemplateId", referencedColumnName="Id")
* @ORM\JoinColumn(name="TemplateId", referencedColumnName="Id", nullable=false)
* @var Newscoop\Entity\Snippet\SnippetTemplate\SnippetTemplateField
*/
protected $field;
Expand Down Expand Up @@ -71,6 +71,32 @@ public function setId($id)
return $this;
}

/**
* Getter for snippet
*
* @return mixed
*/
public function getSnippet()
{
return $this->snippet;
}

/**
* Setter for snippet
*
* @param mixed $snippet Value to set
*
* @return self
*/
public function setSnippet($snippet)
{

$this->snippet = $snippet;

return $this;
}


/**
* Getter for field name
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ public function getFields()
*/
public function addField(SnippetTemplateField $field)
{
$field->setTemplate($this);
$this->fields->add($field);

return $this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SnippetTemplateField

/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Snippet\SnippetTemplate", inversedBy="fields")
* @ORM\JoinColumn(name="TemplateId", referencedColumnName="Id")
* @ORM\JoinColumn(name="TemplateId", referencedColumnName="Id", nullable=false)
* @var Newscoop\Entity\Snippet\SnippetTemplate
*/
protected $template;
Expand Down Expand Up @@ -160,4 +160,28 @@ public function setScope($scope)
return $this;
}

/**
* Getter for template
*
* @return mixed
*/
public function getTemplate()
{
return $this->template;
}

/**
* Setter for template
*
* @param mixed $template Value to set
*
* @return self
*/
public function setTemplate($template)
{
$this->template = $template;

return $this;
}

}

0 comments on commit ffb8653

Please sign in to comment.