mapado/doctrine-blender-bundle

此包已被废弃,不再维护。未建议替代包。

mapado/doctrine-blender 包配置的替代包

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

This package is auto-updated.

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


README

此包负责将https://github.com/mapado/doctrine-blender集成到Symfony项目中。

安装

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

使用

实体

摘自doctrine mongodb文档

首先定义我们的Product文档

/** @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;
    }
}

然后创建一个Order实体,它具有 $product 和 $productId 属性,将其链接到存储在MongoDB中的Product

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;
    }
}

配置

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:
            # ...