symfony2 step by step n.
Download
Skip this Video
Loading SlideShow in 5 Seconds..
Symfony2 - Step-by-step PowerPoint Presentation
Download Presentation
Symfony2 - Step-by-step

Loading in 2 Seconds...

play fullscreen
1 / 17

Symfony2 - Step-by-step - PowerPoint PPT Presentation


  • 85 Views
  • Uploaded on

Symfony2 - Step-by-step. Doctrine ORM Relationship OneToOne ManyToOne OneToMany ManyToMany Self-referencing. Entities. OneToOne. “Blog” vs “Blog Setting” 1 blog has only 1 setting 1 setting only belong to 1 blog. /** @Entity **/ class Blog { // ... /**

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'Symfony2 - Step-by-step' - sebastian-ramirez


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
symfony2 step by step
Symfony2 - Step-by-step
  • Doctrine ORM Relationship
    • OneToOne
    • ManyToOne
    • OneToMany
    • ManyToMany
    • Self-referencing
onetoone
OneToOne
  • “Blog” vs “Blog Setting”
    • 1 blog has only 1 setting
    • 1 setting only belong to 1 blog
slide4

/** @Entity **/

class Blog

{

// ...

/**

* @OneToOne(targetEntity=“BlogSetting")

* @JoinColumn(name=“setting_id", referencedColumnName="id")

**/

private $setting;

// ...

}

/** @Entity **/

class BlogSetting

{

// ...

}

tables
Tables
  • Blog
  • BlogSetting
manytoone and onetomany
ManyToOne and OneToMany
  • “Blog” vs “Post”
    • 1 blog has many posts
    • 1 post only belong to 1 blog
slide8

/** @Entity **/

class Blog

{

// ...

/**

* @ORM\OneToMany(targetEntity="Post", mappedBy="blog", cascade={"remove"})

**/

private $posts;

// ...

}

/** @Entity **/

class Post

{

/**

* @ORM\ManyToOne(targetEntity=“Blog", inversedBy="posts“)

* @ORM\JoinColumn(name="blog_id", referencedColumnName="id")

**/

private $blog;

}

tables1
Tables
  • Blog
  • Post
manytomany
ManyToMany
  • “Post” vs “Category”
    • 1 post can belong to one or many categories
    • 1 category can have one or many posts

1. Post “Singapore tour”

2. Post category “tour”, “relax”, “picture”

3. Post “Nhatrang tour”

4. Post category “tour”

slide12

/** @Entity **/

class Post

{

// ...

/**

* @ORM\ManyToMany(targetEntity="Category", inversedBy="posts")

* @ORM\JoinTable(name="category_post")

**/

private $categories;

// ...

}

/** @Entity **/

class Category

{

/**

* @ORM\ManyToMany(targetEntity="Post", mappedBy="categories")

**/

private $posts;

}

tables2
Tables
  • Category
  • Post
  • Category_Post
onetomany self referencing
OneToMany – Self-referencing
  • “Category” vs “Parent Category”
    • 1 category has 1 parent category
    • 1 parent category has 1 or many children category
slide16

/** @Entity **/

class Category

{

// ...

/**

* @OneToMany(targetEntity="Category", mappedBy="parent")

**/

private $children;

/**

* @ManyToOne(targetEntity="Category", inversedBy="children")

* @JoinColumn(name="parent_id", referencedColumnName="id")

**/

private $parent;

// ...

}

tables3
Tables
  • Category