I am trying to create a symfony2 application. The main idea behind the project is that there is an event which many guests are invited to and they are categorized. I have created a relational model for all the entities.
There are 4 tables:
- Guests - who is invited
- Category - what category/categories he belongs to ?
- Event - the event which they are invited to
- Guest_Event (attendance)
I have concluded to the following schemas:
xxxxBundle\Entity\Guest:
type: entity
table: guest
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 100
nullable: false
surname:
type: string
length: 100
nullable: false
email:
type: string
length: 255
nullable: true
address:
type: string
length: 255
nullable: true
phone:
type: string
length: 10
description:
type: text
created_at:
type: datetime
updated_at:
type: datetime
nullable: true
token:
type: string
length: 255
unique: true
is_activated:
type: boolean
nullable: true
manyToOne:
category:
targetEntity: Category
inversedBy: guest
joinColumn:
name: category_id
referencedColumnName: id
lifecycleCallbacks:
prePersist: [ setCreatedAtValue ]
preUpdate: [ setUpdatedAtValue ]
Category
xxxxBundle\Entity\Category:
type: entity
table: category
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 255
unique: true
oneToMany:
guests:
targetEntity: Guest
mappedBy: category
attend:
targetEntity: Attendance
mappedBy: category
Event
xxxxxBundle\Entity\Event:
type: entity
table: event
id:
id:
type: integer
generator: { strategy: AUTO }
fields:
name:
type: string
length: 100
nullable: false
location:
type: string
length: 255
nullable: true
scheduled_at:
type: datetime
manyToMany:
category:
targetEntity: guest
inversedBy: event
joinColumn:
name: event_id
referencedColumnName: id
- A guest might belong to multiple categories (manyToOne)
- A category will have many guests (manyToOne)
- A guest might attend many events (manyToOne)
- An event might have many attendants (manyToMany?)
- the attendance table (guest_event) should be a join table ?
I am a little bit confused about ORM and doctrine coding. Creating the tables via SQL code or phpmyadmin seems much easier to me but I want to go the hard way ! The documentation seems confusing because each tutorial suggests different things and the doctrine ORM section in the symfony2 book doesn't have a complete example but pieces of code..
How can I correct my tables to include all the specifications ?
nullable=false
(default istrue
) for those foreign keys that can't benull
: docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/… – gremo