mapado/doctrine-blender-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Bundle in change of the mapado/doctrine-blender package configuration

v0.4.1 2016-04-12 12:35 UTC

This package is auto-updated.

Last update: 2023-09-15 20:44:07 UTC


README

This bundle in charge of the https://github.com/mapado/doctrine-blender integration into a Symfony project.

Installation

composer require "mapado/doctrine-blender-bundle:0.*"

Usage

Entities

Taken from doctrine mongodb documentation

First lets define our Product document:

/** @Document */
class Product
{
    /** @Id */
    private $id;

    /** @String */
    private $title;

    public function getId()
    {
        return $this->id;
    }

    public function getTitle()
    {
        return $this->title;
    }

    public function setTitle($title)
    {
        $this->title = $title;
    }
}

Next create the Order entity that has a $product and $productId property linking it to the Product that is stored with MongoDB:

namespace Entities;

use Documents\Product;

/**
 * @Entity
 * @Table(name="orders")
 */
class Order
{
    /**
     * @Id @Column(type="integer")
     * @GeneratedValue(strategy="AUTO")
     */
    private $id;

    /**
     * @Column(type="string")
     */
    private $productId;

    /**
     * @var Documents\Product
     */
    private $product;

    public function getId()
    {
        return $this->id;
    }

    public function getProductId()
    {
        return $this->productId;
    }

    public function setProduct(Product $product)
    {
        $this->productId = $product->getId();
        $this->product = $product;
    }

    public function getProduct()
    {
        return $this->product;
    }
}

Configuration

mapado_doctrine_blender:
    doctrine_external_associations:
        order:
            source_object_manager: 'doctrine.orm.order_entity_manager'
            classname: 'Acme\DemoBundle\Entity\Order'
            references:
                product: # this is the name of the property in the source entity
                    reference_id_getter: 'getProductId' # optional, method in the source entity fetching the ref.id
                    reference_setter: 'setProduct' # optional, method in the source entity to set the reference
                    reference_object_manager: 'doctrine_mongodb.odm.product_document_manager'
                    reference_class: 'Acme\DemoBundle\Document\Product'

                tags: # can also be an array (or an iterator)
                    reference_id_getter: 'getTagIds' # must return an array (or an iterator) of identifiers
                    reference_setter: 'setTags'
                    reference_object_manager: 'doctrine_mongodb.odm.tag_document_manager'
                    reference_class: 'Acme\DemoBundle\Document\Tag'

                another_reference:
                    # ...

        another_source:
            # ...