php - creating multiple onetoMany relations in Sumfony 2.5 -


I'm really new to Symphony so that I can apologize in advanced if it looks stupid and I really appreciate it I am someone to remove my understanding.

I am studying and while reading, I thought why not make Dummy blog app to practice.

The dummy blog app that I'm working on is very easy, just three tables and its

  • <
  • strong> comments (where comments are for posting) its unit unit / comments. Php
  • Category (where post categories go) its unit unit / category.php.

    I am working to save, show, update, delete all posts / categories / comments.

    What I am working after appearing on the blog, its range appears as a number (category id), so I was trying to link the post table with category table

    Question 1 , since the post is linked to the comment table and I need to link the same table of posts with the category table. We will call it the Entity / Post.php

      inside the class {/ ** * @ORM \ O neToMany (target mapped Antiti = "comments" = "post") * / / ** ** @ORM \ ManyToOne (targetEntity = "class", inversedBy = "post") * @ORM \ JoinColumn (name = " Category ", referenced column name =" id ") * / protected $ comment; Protected $ categories;   

    If not, what is the right way to handle these relationships?

    Question 2 , while reading "It seems that I should be able to get the name name range

      $ Posts = $ this- & gt; getDoctrine () - & gt; getRepository ('blogbundle: post') - & gt; findBy (array ('category' = & gt; $ id), array ('id' = & gt ; 'DESC')); $ category_name = $ posts- & gt; Matching-category ();   

    But this is an error to me

      Error: Call a member function at getCategory ()   

    on a non-object, I can confirm that this getCategory (

    - Text "itemprop =" text "> < P> Question 1

    Annotations are fine, but you have to type them at the top of those properties, which they are related to, otherwise they are ignored:

      class post {/ ** * @ORM \ OneToMany (targetEntity = "Comment", map PedBy = "post") * / protected $ comments; / ** * @ORM \ ManyToOne (targetEntity = "category ", InversedBy =" posts ") * @ORM \ JoinColumn (name =" category ", referenced column name =" id ") * / protected $ category; Public Function __constructor () {$ this- & gt; Comments = new ArrayCollection (); } // ...}   

    Be sure that you have the right equivalent set in other organizations:

      class category {/ ** * @ORM \ OneToMany (targetEntity = "Post", mapped = "category") * / protected $ posts; Public Function __constructor () {$ this- & gt; Post = new ArrayCollection (); } // comment} {/ ** * @ORM \ ManyToOne (targetEntity = "post", inversedBy = "comments") * @ORM \ JoinColumn (name = "post", referenced column name = "id") * $ Protected / post; // ...}   

    Note that I have changed the name of some unique / plural properties and comments class. This way should be more intuitive.

    Question 2

    findBy returns an array of objects, even if only one object was found. Use either findOneBy or foreach through your results.

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -