floriansemm / SolrBundle

Solr-Integration into Symfony and Doctrine2
http://floriansemm.github.io/SolrBundle
MIT License
123 stars 72 forks source link

Related entities #112

Closed zquintana closed 8 years ago

zquintana commented 8 years ago

Added related entities support via adding getter name property to the Field annotation. So adding the related entity is as simple as:

    /**
     * @var ArrayCollection
     *
     * @Solr\Field(type="strings", getter="getName")
     * @ORM\ManyToMany(targetEntity="Tag", inversedBy="post")
     * @ORM\JoinTable("posts_tags")
     */
    private $tags;
floriansemm commented 8 years ago

:+1:

I will review/test it later today

floriansemm commented 8 years ago

I have test your pull-request a bit and I found some points:

My config: Post

    /**
     * @var Category
     *
     * @Solr\Field(type="string", getter="getTitle")
     * @ORM\ManyToOne(targetEntity="Acme\DemoBundle\Entity\Category", inversedBy="posts")
     * @ORM\JoinColumn(name="category_id", referencedColumnName="id")
     */
    private $category;

Category

    /**
     * @var Post[]
     *
     * @Solr\Field(type="strings", getter="getTitle")
     * @ORM\OneToMany(targetEntity="Acme\DemoBundle\Entity\Post", mappedBy="category")
     */
    private $posts;
zquintana commented 8 years ago

Looks like the problem was that I didn't have logic in place to make sure the entity was in place. Fix it now. In my latest patch.

zquintana commented 8 years ago

Just realized the this branch I pushed, by accident fixes for the newest solarium versions. I can remove that if need be. Let me know.

surivrox commented 8 years ago

Any update on this?

floriansemm commented 8 years ago

I am working on this "relation-problem", based on this pull-request

zquintana commented 8 years ago

Sorry guys. Here's the update. Problem is that I've added a few more features into my branch. I added VirtualFields properties and fixed an issue with the doctrine hydrator that would query n amount of records from the database during hydration. Switched that to a find all so it would be one query rather then n. I also added a basic DataCollector so that you can see the actual queries being passed to Solr. Problem is that all of that is on my dev branch. @floriansemm how would you like me to arrange this for you to pull in?

Sorry for the delay again. We needed this for a project we're working on so had to build it quickly.

floriansemm commented 8 years ago

@zquintana you can create another pull-request for your new features or attach them to this pull-request. Then I will merge your changes into the zquintana-related_entities branch which contains all the related-entities stuff.