yaml がわかりにくいので、気が変わってアノテーションを使用しました。
ここのところ :
ゲストエンティティの場合
<?php
// xxxxBundle/Entity/Guest.php
namespace xxxxBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\MinLength;
use Symfony\Component\Validator\Constraints\MaxLength;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="guest")
*/
class Guest
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ManyToMany(targetEntity="Category", inversedBy="guests")
* @JoinTable(name="guests_categories")
*/
protected $categories;
/**
* @ManyToMany(targetEntity="Event", inversedBy="events")
* @JoinTable(name="guests_events")
*/
protected $events;
/**
* @ORM\Column(type="string", length=30)
*/
protected $name;
/**
* @ORM\Column(type="string", length=30)
*/
protected $surname;
/**
* @ORM\Column(type="string", length=30)
*/
protected $email;
/**
* @ORM\Column(type="string", length=100)
*/
protected $address;
/**
* @ORM\Column(type="string", length=10)
*/
protected $phone;
/**
* @ORM\Column(type="string", length=10)
*/
protected $mobile;
/**
* @ORM\Column(type="text")
*/
protected $description;
/**
* @ORM\Column(type="datetime")
*/
protected $created_at;
/**
* @ORM\Column(type="datetime")
*/
protected $updated_at;
/**
* @ORM\Column(type="string")
*/
protected $token;
/**
* @ORM\Column(type="boolean")
*/
protected $is_activated;
public function __construct() {
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
$metadata->addPropertyConstraint('surname', new NotBlank());
$metadata->addPropertyConstraint('email', new Email(array(
'message' => 'I do not like invalid emails. Give me a real one!')));
$metadata->addPropertyConstraint('phone', new MaxLength(10));
$metadata->addPropertyConstraint('mobile', new MaxLength(10));
}
}
カテゴリエンティティの場合
<?php
// xxxxBundle/Entity/Category.php
namespace xxxxBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\MinLength;
use Symfony\Component\Validator\Constraints\MaxLength;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="category")
*/
class Category
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ManyToMany(targetEntity="Guest", mappedBy="categories")
*/
protected $guests;
/**
* @ORM\Column(type="string", length=30)
*/
protected $name;
/**
* @ORM\Column(type="text")
*/
protected $description;
public function __construct() {
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
}
}
Eventエンティティの場合
<?php
// xxxxBundle/Entity/Event.php
namespace xxxxBundle\Entity;
use Symfony\Component\Validator\Mapping\ClassMetadata;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\MinLength;
use Symfony\Component\Validator\Constraints\MaxLength;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="event")
*/
class Event
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ManyToMany(targetEntity="Guest", mappedBy="categories")
*/
protected $guests;
/**
* @ORM\Column(type="string", length=30)
*/
protected $name;
/**
* @ORM\Column(type="string", length=100)
*/
protected $location;
/**
* @ORM\Column(type="text")
*/
protected $description;
/**
* @ORM\Column(type="datetime")
*/
protected $scheduled_at;
public function __construct() {
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
public static function loadValidatorMetadata(ClassMetadata $metadata)
{
$metadata->addPropertyConstraint('name', new NotBlank());
$metadata->addPropertyConstraint('location', new NotBlank());
}
}
出席エンティティについて混乱しています。Attendance エンティティには、次の変数があります。
- Guest_id
- Event_id
- Will_attend (はい/いいえ/多分)
- コメント
- Reply_at
- Updated_at
どちらが主キーになるかわかりません (または主キー?)。db テーブルに個別の ID を付ける必要はありません (または付けない?)。
<?php
// xxxxBundle/Entity/Attendance.php
namespace xxxxBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="attendance")
*/
class Attendance
{
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ManyToMany(targetEntity="Guest", mappedBy="categories")
*/
protected $guests;
/**
* @ManyToMany(targetEntity="Event", mappedBy="events")
*/
protected $events;
/**
* @ORM\Column(type="string", length=3)
*/
protected $will_attend;
/**
* @ORM\Column(type="text")
*/
protected $description;
/**
* @ORM\Column(type="datetime")
*/
protected $replied_at;
public function __construct() {
$this->categories = new \Doctrine\Common\Collections\ArrayCollection();
}
}