Php 一对多/多对一原则。不起作用

Php 一对多/多对一原则。不起作用,php,orm,doctrine-orm,Php,Orm,Doctrine Orm,几天来,我一直在努力解决这个问题,但运气不佳 首先是一些澄清: 基本上,我想在“用户”和“商店”之间建立关系,我的计划是识别特定用户最喜欢的商店,并且从商店的角度来看,在一个特定商店中购物的人是他们最喜欢的商店。 我的猜测是使用多人关系,但在查找了相关示例后,许多网站描述,如果您需要多人关系和其他字段(在我的例子中,我有3个附加字段),则必须使用一人/多人关系 我在数据库中使用SQLITE只是为了开发,我在PHP中使用Slim框架编写RESTAPI 当使用这样的方法获取特定实体时,一切都正常工作

几天来,我一直在努力解决这个问题,但运气不佳

首先是一些澄清:

基本上,我想在“用户”和“商店”之间建立关系,我的计划是识别特定用户最喜欢的商店,并且从商店的角度来看,在一个特定商店中购物的人是他们最喜欢的商店。 我的猜测是使用多人关系,但在查找了相关示例后,许多网站描述,如果您需要多人关系和其他字段(在我的例子中,我有3个附加字段),则必须使用一人/多人关系

我在数据库中使用SQLITE只是为了开发,我在PHP中使用Slim框架编写RESTAPI

当使用这样的方法获取特定实体时,一切都正常工作

/**
     * Fetching user by email
     * @param String $email User email
     */
    public function getUserByEmail($email) {
    $user = $this->getEntityManager()->getRepository('User')
                                     ->findOneBy(array('email' => $email));
    if ($user === null) {
        return null;
    } else {
        return $user;
    }
}

一旦我得到任何实体,我就可以读取它们的属性。除非我试图获得以下信息:

echo $User->getShopsAt(); i get an error saying "Object of class Doctrine\ORM\PersistentCollection could not be converted to string"
如果我尝试

echo [$User->getShopsAt()]; i get "Array" as reponse
echo count([$User->getShopsAt()]); i get 1
如果我尝试

echo [$User->getShopsAt()]; i get "Array" as reponse
echo count([$User->getShopsAt()]); i get 1
如果我理解,对getShopsAt()的调用应该返回与用户id匹配的“UserStore”实体的所有实例,但我无法访问其任何属性。 我尝试过的一切都失败了,我还想指出,我使用了用户Id“1”,在“UserStore”表中有2个条目。那么,为什么计数返回1。

我使用YML格式创建了3模式,因为我发现它比PHP更清晰

通过这些模式,我使用命令“vendor/bin/orm:generate entities./src”创建了实体(请参见底部的结果实体)

然后,我使用vendor/bin/orm:schema工具:update--force创建数据库模式(请参见底部的数据库SQL和数据)

之后,我在Chrome浏览器上使用升级的REST客户端扩展在数据库上创建了一些数据。但我已经独立创建了所有这些。这意味着,首先创建用户而不将任何内容设置为shopsAt属性,然后创建一些商店而不将任何内容设置为Shopsers属性,然后创建一些UserStores

重要问题: 在创建UserStore的过程中,我必须恢复实际的用户和Store,以设置其关系的反向端

不,仅仅向UserStore添加正确的密钥和条令将在读取用户/存储时进行匹配,因为UserStore的创建就足够了,因为它是关系的拥有方

我必须手动修改由orm:generate entities命令自动生成的实体,并在UserStore的setStore和setUser方法中更新反转侧?如上所述

我的数据库如下所示:

USER:

CREATE TABLE users (id INTEGER NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(50) NOT NULL, password_hash VARCHAR(255) NOT NULL, api_key VARCHAR(32) NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(id))

ROW 1 = "1","user1","user1@mail.com","xxxxxxxxxxxxxxxx","yyyyyyyyyyyyyy","1","2015-06-27 17:16:01","2015-06-27 17:16:01"
ROW 2 = "2","user2","user2@mail.com","xxxxxxxxxxxxxxxx","yyyyyyyyyyyyyy","1","2015-06-27 17:38:36","2015-06-27 17:38:36"

STORE:

CREATE TABLE stores (id INTEGER NOT NULL, brand_id INTEGER DEFAULT NULL, neighborhood_id INTEGER DEFAULT NULL, county_id INTEGER DEFAULT NULL, city_id INTEGER DEFAULT NULL, state_id INTEGER DEFAULT NULL, streetname VARCHAR(255) NOT NULL COLLATE BINARY, streetnumber VARCHAR(255) NOT NULL COLLATE BINARY, cp VARCHAR(255) NOT NULL COLLATE BINARY, lat VARCHAR(255) NOT NULL COLLATE BINARY, lng VARCHAR(255) NOT NULL COLLATE BINARY, favorite INTEGER NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_D5907CCC44F5D008 FOREIGN KEY (brand_id) REFERENCES brands (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC803BB24B FOREIGN KEY (neighborhood_id) REFERENCES neighborhoods (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC85E73F45 FOREIGN KEY (county_id) REFERENCES counties (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC8BAC62AF FOREIGN KEY (city_id) REFERENCES cities (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC5D83CC1 FOREIGN KEY (state_id) REFERENCES states (id) NOT DEFERRABLE INITIALLY IMMEDIATE)

ROW 1 = "1","1","1","1","1","1","streetname 1","11111","1234","0.0000000","1.1111111","1","1","2015-06-06 02:32:19","2015-06-06 02:32:19"
ROW 2 = "2","4","2","2","2","2","streetname 2","2222","1234","0.000000","1.000000","0","1","2015-06-27 17:50:24","2015-06-27 17:50:24"

USERSTORE:

CREATE TABLE UsersStores (user_id INTEGER NOT NULL, store_id INTEGER NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(user_id, store_id), CONSTRAINT FK_39EFBEF8A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_39EFBEF8B092A811 FOREIGN KEY (store_id) REFERENCES stores (id) NOT DEFERRABLE INITIALLY IMMEDIATE)

VALUES:
ROW 1 = "2","1","1","2015-06-28 17:51:40","2015-06-28 17:51:40"
ROW 2 = "1","2","1","2015-06-28 17:51:51","2015-06-28 17:51:51"
ROW 3 = "1","1","1","2015-06-28 20:51:53","2015-06-28 20:51:53"



User:
  type: entity
  table: users

  id:
    id:
      type: integer
      generator:
        strategy: auto
  fields:
    name:
      type: string(255)
    email:
      type: string(50)
    password_hash:
      type: string(255)
    api_key:
      type: string(32)
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  oneToMany:
    shopsAt:
      targetEntity: UserStore
      mappedBy: product

///////////////////////////////////

Store:
  type: entity
  table: stores
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    streetname:
      type: string
    streetnumber:
      type: string(255)
    cp:
      type: string(255)
    lat:
      type: string(255)
    lng:
      type: string(255)
    favorite:
      type: integer(1)
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  oneToMany:
    productsAvailable:
      targetEntity: ProductStore
      mappedBy: store
    shoppers:
      targetEntity: UserStore
      mappedBy: store

  manyToOne:
    brand:
      targetEntity: Brand
      joinColumn:
        name: brand_id
        referencedColumnName: id
    neighborhood:
      targetEntity: Neighborhood
      joinColumn:
        name: neighborhood_id
        referencedColumnName: id
    county:
      targetEntity: County
      joinColumn:
        name: county_id
        referencedColumnName: id
    city:
      targetEntity: City
      joinColumn:
        name: city_id
        referencedColumnName: id
    state:
      targetEntity: State
      joinColumn:
        name: state_id
        referencedColumnName: id


//////////////////////////////////////

UserStore:
  type: entity
  table: UsersStores

  id:
    user:
      associationKey: true
    store:
      associationKey: true
  fields:
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  manyToOne:
    user:
      targetEntity: User
      inversedBy: shopsAt
      joinColumn:
        name: user_id
        referencedColumnName: id
    store:
      targetEntity: Store
      inversedBy: shoppers
      joinColumn:
        name: store_id
        referencedColumnName: id


//////////////////////////////////////

use Doctrine\ORM\Mapping as ORM;

/**
 * User
 */
class User
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $email;

    /**
     * @var string
     */
    private $password_hash;

    /**
     * @var string
     */
    private $api_key;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return User
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set password_hash
     *
     * @param string $passwordHash
     * @return User
     */
    public function setPasswordHash($passwordHash)
    {
        $this->password_hash = $passwordHash;

        return $this;
    }

    /**
     * Get password_hash
     *
     * @return string 
     */
    public function getPasswordHash()
    {
        return $this->password_hash;
    }

    /**
     * Set api_key
     *
     * @param string $apiKey
     * @return User
     */
    public function setApiKey($apiKey)
    {
        $this->api_key = $apiKey;

        return $this;
    }

    /**
     * Get api_key
     *
     * @return string 
     */
    public function getApiKey()
    {
        return $this->api_key;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return User
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return User
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return User
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $shopsAt;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->shopsAt = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add shopsAt
     *
     * @param \UserStore $shopsAt
     * @return User
     */
    public function addShopsAt(\UserStore $shopsAt)
    {
        $this->shopsAt[] = $shopsAt;

        return $this;
    }

    /**
     * Remove shopsAt
     *
     * @param \UserStore $shopsAt
     */
    public function removeShopsAt(\UserStore $shopsAt)
    {
        $this->shopsAt->removeElement($shopsAt);
    }

    /**
     * Get shopsAt
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getShopsAt()
    {
        return $this->shopsAt;
    }
}

///////////////////////////////////////

use Doctrine\ORM\Mapping as ORM;

/**
 * Store
 */
class Store
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $streetname;

    /**
     * @var string
     */
    private $streetnumber;

    /**
     * @var string
     */
    private $cp;

    /**
     * @var string
     */
    private $lat;

    /**
     * @var string
     */
    private $lng;

    /**
     * @var integer
     */
    private $favorite;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $productsAvailable;

    /**
     * @var \Brand
     */
    private $brand;

    /**
     * @var \Neighborhood
     */
    private $neighborhood;

    /**
     * @var \County
     */
    private $county;

    /**
     * @var \City
     */
    private $city;

    /**
     * @var \State
     */
    private $state;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->productsAvailable = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set streetname
     *
     * @param string $streetname
     * @return Store
     */
    public function setStreetname($streetname)
    {
        $this->streetname = $streetname;

        return $this;
    }

    /**
     * Get streetname
     *
     * @return string 
     */
    public function getStreetname()
    {
        return $this->streetname;
    }

    /**
     * Set streetnumber
     *
     * @param string $streetnumber
     * @return Store
     */
    public function setStreetnumber($streetnumber)
    {
        $this->streetnumber = $streetnumber;

        return $this;
    }

    /**
     * Get streetnumber
     *
     * @return string 
     */
    public function getStreetnumber()
    {
        return $this->streetnumber;
    }

    /**
     * Set cp
     *
     * @param string $cp
     * @return Store
     */
    public function setCp($cp)
    {
        $this->cp = $cp;

        return $this;
    }

    /**
     * Get cp
     *
     * @return string 
     */
    public function getCp()
    {
        return $this->cp;
    }

    /**
     * Set lat
     *
     * @param string $lat
     * @return Store
     */
    public function setLat($lat)
    {
        $this->lat = $lat;

        return $this;
    }

    /**
     * Get lat
     *
     * @return string 
     */
    public function getLat()
    {
        return $this->lat;
    }

    /**
     * Set lng
     *
     * @param string $lng
     * @return Store
     */
    public function setLng($lng)
    {
        $this->lng = $lng;

        return $this;
    }

    /**
     * Get lng
     *
     * @return string 
     */
    public function getLng()
    {
        return $this->lng;
    }

    /**
     * Set favorite
     *
     * @param integer $favorite
     * @return Store
     */
    public function setFavorite($favorite)
    {
        $this->favorite = $favorite;

        return $this;
    }

    /**
     * Get favorite
     *
     * @return integer 
     */
    public function getFavorite()
    {
        return $this->favorite;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return Store
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return Store
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return Store
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Add productsAvailable
     *
     * @param \ProductStore $productsAvailable
     * @return Store
     */
    public function addProductsAvailable(\ProductStore $productsAvailable)
    {
        $this->productsAvailable[] = $productsAvailable;

        return $this;
    }

    /**
     * Remove productsAvailable
     *
     * @param \ProductStore $productsAvailable
     */
    public function removeProductsAvailable(\ProductStore $productsAvailable)
    {
        $this->productsAvailable->removeElement($productsAvailable);
    }

    /**
     * Get productsAvailable
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getProductsAvailable()
    {
        return $this->productsAvailable;
    }

    /**
     * Set brand
     *
     * @param \Brand $brand
     * @return Store
     */
    public function setBrand(\Brand $brand = null)
    {
        $this->brand = $brand;

        return $this;
    }

    /**
     * Get brand
     *
     * @return \Brand 
     */
    public function getBrand()
    {
        return $this->brand;
    }

    /**
     * Set neighborhood
     *
     * @param \Neighborhood $neighborhood
     * @return Store
     */
    public function setNeighborhood(\Neighborhood $neighborhood = null)
    {
        $this->neighborhood = $neighborhood;

        return $this;
    }

    /**
     * Get neighborhood
     *
     * @return \Neighborhood 
     */
    public function getNeighborhood()
    {
        return $this->neighborhood;
    }

    /**
     * Set county
     *
     * @param \County $county
     * @return Store
     */
    public function setCounty(\County $county = null)
    {
        $this->county = $county;

        return $this;
    }

    /**
     * Get county
     *
     * @return \County 
     */
    public function getCounty()
    {
        return $this->county;
    }

    /**
     * Set city
     *
     * @param \City $city
     * @return Store
     */
    public function setCity(\City $city = null)
    {
        $this->city = $city;

        return $this;
    }

    /**
     * Get city
     *
     * @return \City 
     */
    public function getCity()
    {
        return $this->city;
    }

    /**
     * Set state
     *
     * @param \State $state
     * @return Store
     */
    public function setState(\State $state = null)
    {
        $this->state = $state;

        return $this;
    }

    /**
     * Get state
     *
     * @return \State 
     */
    public function getState()
    {
        return $this->state;
    }
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $shoppers;


    /**
     * Add shoppers
     *
     * @param \UserStore $shoppers
     * @return Store
     */
    public function addShopper(\UserStore $shoppers)
    {
        $this->shoppers[] = $shoppers;

        return $this;
    }

    /**
     * Remove shoppers
     *
     * @param \UserStore $shoppers
     */
    public function removeShopper(\UserStore $shoppers)
    {
        $this->shoppers->removeElement($shoppers);
    }

    /**
     * Get shoppers
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getShoppers()
    {
        return $this->shoppers;
    }
}


//////////////////////////////////////////////////


use Doctrine\ORM\Mapping as ORM;

/**
 * UserStore
 */
class UserStore
{
    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    /**
     * @var \User
     */
    private $user;

    /**
     * @var \Store
     */
    private $store;


    /**
     * Set status
     *
     * @param integer $status
     * @return UserStore
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return UserStore
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return UserStore
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Set user
     *
     * @param \User $user
     * @return UserStore
     */
    public function setUser(\User $user)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \User 
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Set store
     *
     * @param \Store $store
     * @return UserStore
     */
    public function setStore(\Store $store)
    {
        $this->store = $store;

        return $this;
    }

    /**
     * Get store
     *
     * @return \Store 
     */
    public function getStore()
    {
        return $this->store;
    }

}
foreach ($User->getShopsAt() as $user_store) {
   echo $user_store->getStatus();
   echo $user_store->getCreate at();
}
$User->getShopsAt()->count()
count($User->getShopsAt()) <-- note I am NOT wrapping it in []
当你打电话时:

$User->getShopsAt()

您将收到一个\doctor\Common\Collections\ArrayCollection()对象,该对象表示一个结果数组。您可以像这样对其进行迭代:

USER:

CREATE TABLE users (id INTEGER NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(50) NOT NULL, password_hash VARCHAR(255) NOT NULL, api_key VARCHAR(32) NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(id))

ROW 1 = "1","user1","user1@mail.com","xxxxxxxxxxxxxxxx","yyyyyyyyyyyyyy","1","2015-06-27 17:16:01","2015-06-27 17:16:01"
ROW 2 = "2","user2","user2@mail.com","xxxxxxxxxxxxxxxx","yyyyyyyyyyyyyy","1","2015-06-27 17:38:36","2015-06-27 17:38:36"

STORE:

CREATE TABLE stores (id INTEGER NOT NULL, brand_id INTEGER DEFAULT NULL, neighborhood_id INTEGER DEFAULT NULL, county_id INTEGER DEFAULT NULL, city_id INTEGER DEFAULT NULL, state_id INTEGER DEFAULT NULL, streetname VARCHAR(255) NOT NULL COLLATE BINARY, streetnumber VARCHAR(255) NOT NULL COLLATE BINARY, cp VARCHAR(255) NOT NULL COLLATE BINARY, lat VARCHAR(255) NOT NULL COLLATE BINARY, lng VARCHAR(255) NOT NULL COLLATE BINARY, favorite INTEGER NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_D5907CCC44F5D008 FOREIGN KEY (brand_id) REFERENCES brands (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC803BB24B FOREIGN KEY (neighborhood_id) REFERENCES neighborhoods (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC85E73F45 FOREIGN KEY (county_id) REFERENCES counties (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC8BAC62AF FOREIGN KEY (city_id) REFERENCES cities (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC5D83CC1 FOREIGN KEY (state_id) REFERENCES states (id) NOT DEFERRABLE INITIALLY IMMEDIATE)

ROW 1 = "1","1","1","1","1","1","streetname 1","11111","1234","0.0000000","1.1111111","1","1","2015-06-06 02:32:19","2015-06-06 02:32:19"
ROW 2 = "2","4","2","2","2","2","streetname 2","2222","1234","0.000000","1.000000","0","1","2015-06-27 17:50:24","2015-06-27 17:50:24"

USERSTORE:

CREATE TABLE UsersStores (user_id INTEGER NOT NULL, store_id INTEGER NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(user_id, store_id), CONSTRAINT FK_39EFBEF8A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_39EFBEF8B092A811 FOREIGN KEY (store_id) REFERENCES stores (id) NOT DEFERRABLE INITIALLY IMMEDIATE)

VALUES:
ROW 1 = "2","1","1","2015-06-28 17:51:40","2015-06-28 17:51:40"
ROW 2 = "1","2","1","2015-06-28 17:51:51","2015-06-28 17:51:51"
ROW 3 = "1","1","1","2015-06-28 20:51:53","2015-06-28 20:51:53"



User:
  type: entity
  table: users

  id:
    id:
      type: integer
      generator:
        strategy: auto
  fields:
    name:
      type: string(255)
    email:
      type: string(50)
    password_hash:
      type: string(255)
    api_key:
      type: string(32)
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  oneToMany:
    shopsAt:
      targetEntity: UserStore
      mappedBy: product

///////////////////////////////////

Store:
  type: entity
  table: stores
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    streetname:
      type: string
    streetnumber:
      type: string(255)
    cp:
      type: string(255)
    lat:
      type: string(255)
    lng:
      type: string(255)
    favorite:
      type: integer(1)
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  oneToMany:
    productsAvailable:
      targetEntity: ProductStore
      mappedBy: store
    shoppers:
      targetEntity: UserStore
      mappedBy: store

  manyToOne:
    brand:
      targetEntity: Brand
      joinColumn:
        name: brand_id
        referencedColumnName: id
    neighborhood:
      targetEntity: Neighborhood
      joinColumn:
        name: neighborhood_id
        referencedColumnName: id
    county:
      targetEntity: County
      joinColumn:
        name: county_id
        referencedColumnName: id
    city:
      targetEntity: City
      joinColumn:
        name: city_id
        referencedColumnName: id
    state:
      targetEntity: State
      joinColumn:
        name: state_id
        referencedColumnName: id


//////////////////////////////////////

UserStore:
  type: entity
  table: UsersStores

  id:
    user:
      associationKey: true
    store:
      associationKey: true
  fields:
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  manyToOne:
    user:
      targetEntity: User
      inversedBy: shopsAt
      joinColumn:
        name: user_id
        referencedColumnName: id
    store:
      targetEntity: Store
      inversedBy: shoppers
      joinColumn:
        name: store_id
        referencedColumnName: id


//////////////////////////////////////

use Doctrine\ORM\Mapping as ORM;

/**
 * User
 */
class User
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $email;

    /**
     * @var string
     */
    private $password_hash;

    /**
     * @var string
     */
    private $api_key;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return User
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set password_hash
     *
     * @param string $passwordHash
     * @return User
     */
    public function setPasswordHash($passwordHash)
    {
        $this->password_hash = $passwordHash;

        return $this;
    }

    /**
     * Get password_hash
     *
     * @return string 
     */
    public function getPasswordHash()
    {
        return $this->password_hash;
    }

    /**
     * Set api_key
     *
     * @param string $apiKey
     * @return User
     */
    public function setApiKey($apiKey)
    {
        $this->api_key = $apiKey;

        return $this;
    }

    /**
     * Get api_key
     *
     * @return string 
     */
    public function getApiKey()
    {
        return $this->api_key;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return User
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return User
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return User
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $shopsAt;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->shopsAt = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add shopsAt
     *
     * @param \UserStore $shopsAt
     * @return User
     */
    public function addShopsAt(\UserStore $shopsAt)
    {
        $this->shopsAt[] = $shopsAt;

        return $this;
    }

    /**
     * Remove shopsAt
     *
     * @param \UserStore $shopsAt
     */
    public function removeShopsAt(\UserStore $shopsAt)
    {
        $this->shopsAt->removeElement($shopsAt);
    }

    /**
     * Get shopsAt
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getShopsAt()
    {
        return $this->shopsAt;
    }
}

///////////////////////////////////////

use Doctrine\ORM\Mapping as ORM;

/**
 * Store
 */
class Store
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $streetname;

    /**
     * @var string
     */
    private $streetnumber;

    /**
     * @var string
     */
    private $cp;

    /**
     * @var string
     */
    private $lat;

    /**
     * @var string
     */
    private $lng;

    /**
     * @var integer
     */
    private $favorite;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $productsAvailable;

    /**
     * @var \Brand
     */
    private $brand;

    /**
     * @var \Neighborhood
     */
    private $neighborhood;

    /**
     * @var \County
     */
    private $county;

    /**
     * @var \City
     */
    private $city;

    /**
     * @var \State
     */
    private $state;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->productsAvailable = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set streetname
     *
     * @param string $streetname
     * @return Store
     */
    public function setStreetname($streetname)
    {
        $this->streetname = $streetname;

        return $this;
    }

    /**
     * Get streetname
     *
     * @return string 
     */
    public function getStreetname()
    {
        return $this->streetname;
    }

    /**
     * Set streetnumber
     *
     * @param string $streetnumber
     * @return Store
     */
    public function setStreetnumber($streetnumber)
    {
        $this->streetnumber = $streetnumber;

        return $this;
    }

    /**
     * Get streetnumber
     *
     * @return string 
     */
    public function getStreetnumber()
    {
        return $this->streetnumber;
    }

    /**
     * Set cp
     *
     * @param string $cp
     * @return Store
     */
    public function setCp($cp)
    {
        $this->cp = $cp;

        return $this;
    }

    /**
     * Get cp
     *
     * @return string 
     */
    public function getCp()
    {
        return $this->cp;
    }

    /**
     * Set lat
     *
     * @param string $lat
     * @return Store
     */
    public function setLat($lat)
    {
        $this->lat = $lat;

        return $this;
    }

    /**
     * Get lat
     *
     * @return string 
     */
    public function getLat()
    {
        return $this->lat;
    }

    /**
     * Set lng
     *
     * @param string $lng
     * @return Store
     */
    public function setLng($lng)
    {
        $this->lng = $lng;

        return $this;
    }

    /**
     * Get lng
     *
     * @return string 
     */
    public function getLng()
    {
        return $this->lng;
    }

    /**
     * Set favorite
     *
     * @param integer $favorite
     * @return Store
     */
    public function setFavorite($favorite)
    {
        $this->favorite = $favorite;

        return $this;
    }

    /**
     * Get favorite
     *
     * @return integer 
     */
    public function getFavorite()
    {
        return $this->favorite;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return Store
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return Store
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return Store
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Add productsAvailable
     *
     * @param \ProductStore $productsAvailable
     * @return Store
     */
    public function addProductsAvailable(\ProductStore $productsAvailable)
    {
        $this->productsAvailable[] = $productsAvailable;

        return $this;
    }

    /**
     * Remove productsAvailable
     *
     * @param \ProductStore $productsAvailable
     */
    public function removeProductsAvailable(\ProductStore $productsAvailable)
    {
        $this->productsAvailable->removeElement($productsAvailable);
    }

    /**
     * Get productsAvailable
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getProductsAvailable()
    {
        return $this->productsAvailable;
    }

    /**
     * Set brand
     *
     * @param \Brand $brand
     * @return Store
     */
    public function setBrand(\Brand $brand = null)
    {
        $this->brand = $brand;

        return $this;
    }

    /**
     * Get brand
     *
     * @return \Brand 
     */
    public function getBrand()
    {
        return $this->brand;
    }

    /**
     * Set neighborhood
     *
     * @param \Neighborhood $neighborhood
     * @return Store
     */
    public function setNeighborhood(\Neighborhood $neighborhood = null)
    {
        $this->neighborhood = $neighborhood;

        return $this;
    }

    /**
     * Get neighborhood
     *
     * @return \Neighborhood 
     */
    public function getNeighborhood()
    {
        return $this->neighborhood;
    }

    /**
     * Set county
     *
     * @param \County $county
     * @return Store
     */
    public function setCounty(\County $county = null)
    {
        $this->county = $county;

        return $this;
    }

    /**
     * Get county
     *
     * @return \County 
     */
    public function getCounty()
    {
        return $this->county;
    }

    /**
     * Set city
     *
     * @param \City $city
     * @return Store
     */
    public function setCity(\City $city = null)
    {
        $this->city = $city;

        return $this;
    }

    /**
     * Get city
     *
     * @return \City 
     */
    public function getCity()
    {
        return $this->city;
    }

    /**
     * Set state
     *
     * @param \State $state
     * @return Store
     */
    public function setState(\State $state = null)
    {
        $this->state = $state;

        return $this;
    }

    /**
     * Get state
     *
     * @return \State 
     */
    public function getState()
    {
        return $this->state;
    }
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $shoppers;


    /**
     * Add shoppers
     *
     * @param \UserStore $shoppers
     * @return Store
     */
    public function addShopper(\UserStore $shoppers)
    {
        $this->shoppers[] = $shoppers;

        return $this;
    }

    /**
     * Remove shoppers
     *
     * @param \UserStore $shoppers
     */
    public function removeShopper(\UserStore $shoppers)
    {
        $this->shoppers->removeElement($shoppers);
    }

    /**
     * Get shoppers
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getShoppers()
    {
        return $this->shoppers;
    }
}


//////////////////////////////////////////////////


use Doctrine\ORM\Mapping as ORM;

/**
 * UserStore
 */
class UserStore
{
    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    /**
     * @var \User
     */
    private $user;

    /**
     * @var \Store
     */
    private $store;


    /**
     * Set status
     *
     * @param integer $status
     * @return UserStore
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return UserStore
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return UserStore
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Set user
     *
     * @param \User $user
     * @return UserStore
     */
    public function setUser(\User $user)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \User 
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Set store
     *
     * @param \Store $store
     * @return UserStore
     */
    public function setStore(\Store $store)
    {
        $this->store = $store;

        return $this;
    }

    /**
     * Get store
     *
     * @return \Store 
     */
    public function getStore()
    {
        return $this->store;
    }

}
foreach ($User->getShopsAt() as $user_store) {
   echo $user_store->getStatus();
   echo $user_store->getCreate at();
}
$User->getShopsAt()->count()
count($User->getShopsAt()) <-- note I am NOT wrapping it in []
等等,或者测试有多少这样的结果:

USER:

CREATE TABLE users (id INTEGER NOT NULL, name VARCHAR(255) NOT NULL, email VARCHAR(50) NOT NULL, password_hash VARCHAR(255) NOT NULL, api_key VARCHAR(32) NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(id))

ROW 1 = "1","user1","user1@mail.com","xxxxxxxxxxxxxxxx","yyyyyyyyyyyyyy","1","2015-06-27 17:16:01","2015-06-27 17:16:01"
ROW 2 = "2","user2","user2@mail.com","xxxxxxxxxxxxxxxx","yyyyyyyyyyyyyy","1","2015-06-27 17:38:36","2015-06-27 17:38:36"

STORE:

CREATE TABLE stores (id INTEGER NOT NULL, brand_id INTEGER DEFAULT NULL, neighborhood_id INTEGER DEFAULT NULL, county_id INTEGER DEFAULT NULL, city_id INTEGER DEFAULT NULL, state_id INTEGER DEFAULT NULL, streetname VARCHAR(255) NOT NULL COLLATE BINARY, streetnumber VARCHAR(255) NOT NULL COLLATE BINARY, cp VARCHAR(255) NOT NULL COLLATE BINARY, lat VARCHAR(255) NOT NULL COLLATE BINARY, lng VARCHAR(255) NOT NULL COLLATE BINARY, favorite INTEGER NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(id), CONSTRAINT FK_D5907CCC44F5D008 FOREIGN KEY (brand_id) REFERENCES brands (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC803BB24B FOREIGN KEY (neighborhood_id) REFERENCES neighborhoods (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC85E73F45 FOREIGN KEY (county_id) REFERENCES counties (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC8BAC62AF FOREIGN KEY (city_id) REFERENCES cities (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_D5907CCC5D83CC1 FOREIGN KEY (state_id) REFERENCES states (id) NOT DEFERRABLE INITIALLY IMMEDIATE)

ROW 1 = "1","1","1","1","1","1","streetname 1","11111","1234","0.0000000","1.1111111","1","1","2015-06-06 02:32:19","2015-06-06 02:32:19"
ROW 2 = "2","4","2","2","2","2","streetname 2","2222","1234","0.000000","1.000000","0","1","2015-06-27 17:50:24","2015-06-27 17:50:24"

USERSTORE:

CREATE TABLE UsersStores (user_id INTEGER NOT NULL, store_id INTEGER NOT NULL, status INTEGER NOT NULL, createdAt DATETIME NOT NULL, updatedAt DATETIME NOT NULL, PRIMARY KEY(user_id, store_id), CONSTRAINT FK_39EFBEF8A76ED395 FOREIGN KEY (user_id) REFERENCES users (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_39EFBEF8B092A811 FOREIGN KEY (store_id) REFERENCES stores (id) NOT DEFERRABLE INITIALLY IMMEDIATE)

VALUES:
ROW 1 = "2","1","1","2015-06-28 17:51:40","2015-06-28 17:51:40"
ROW 2 = "1","2","1","2015-06-28 17:51:51","2015-06-28 17:51:51"
ROW 3 = "1","1","1","2015-06-28 20:51:53","2015-06-28 20:51:53"



User:
  type: entity
  table: users

  id:
    id:
      type: integer
      generator:
        strategy: auto
  fields:
    name:
      type: string(255)
    email:
      type: string(50)
    password_hash:
      type: string(255)
    api_key:
      type: string(32)
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  oneToMany:
    shopsAt:
      targetEntity: UserStore
      mappedBy: product

///////////////////////////////////

Store:
  type: entity
  table: stores
  id:
    id:
      type: integer
      generator:
        strategy: AUTO
  fields:
    streetname:
      type: string
    streetnumber:
      type: string(255)
    cp:
      type: string(255)
    lat:
      type: string(255)
    lng:
      type: string(255)
    favorite:
      type: integer(1)
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  oneToMany:
    productsAvailable:
      targetEntity: ProductStore
      mappedBy: store
    shoppers:
      targetEntity: UserStore
      mappedBy: store

  manyToOne:
    brand:
      targetEntity: Brand
      joinColumn:
        name: brand_id
        referencedColumnName: id
    neighborhood:
      targetEntity: Neighborhood
      joinColumn:
        name: neighborhood_id
        referencedColumnName: id
    county:
      targetEntity: County
      joinColumn:
        name: county_id
        referencedColumnName: id
    city:
      targetEntity: City
      joinColumn:
        name: city_id
        referencedColumnName: id
    state:
      targetEntity: State
      joinColumn:
        name: state_id
        referencedColumnName: id


//////////////////////////////////////

UserStore:
  type: entity
  table: UsersStores

  id:
    user:
      associationKey: true
    store:
      associationKey: true
  fields:
    status:
      type: integer(1)
    createdAt:
      type: datetime
    updatedAt:
      type: datetime

  manyToOne:
    user:
      targetEntity: User
      inversedBy: shopsAt
      joinColumn:
        name: user_id
        referencedColumnName: id
    store:
      targetEntity: Store
      inversedBy: shoppers
      joinColumn:
        name: store_id
        referencedColumnName: id


//////////////////////////////////////

use Doctrine\ORM\Mapping as ORM;

/**
 * User
 */
class User
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $name;

    /**
     * @var string
     */
    private $email;

    /**
     * @var string
     */
    private $password_hash;

    /**
     * @var string
     */
    private $api_key;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;


    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set name
     *
     * @param string $name
     * @return User
     */
    public function setName($name)
    {
        $this->name = $name;

        return $this;
    }

    /**
     * Get name
     *
     * @return string 
     */
    public function getName()
    {
        return $this->name;
    }

    /**
     * Set email
     *
     * @param string $email
     * @return User
     */
    public function setEmail($email)
    {
        $this->email = $email;

        return $this;
    }

    /**
     * Get email
     *
     * @return string 
     */
    public function getEmail()
    {
        return $this->email;
    }

    /**
     * Set password_hash
     *
     * @param string $passwordHash
     * @return User
     */
    public function setPasswordHash($passwordHash)
    {
        $this->password_hash = $passwordHash;

        return $this;
    }

    /**
     * Get password_hash
     *
     * @return string 
     */
    public function getPasswordHash()
    {
        return $this->password_hash;
    }

    /**
     * Set api_key
     *
     * @param string $apiKey
     * @return User
     */
    public function setApiKey($apiKey)
    {
        $this->api_key = $apiKey;

        return $this;
    }

    /**
     * Get api_key
     *
     * @return string 
     */
    public function getApiKey()
    {
        return $this->api_key;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return User
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return User
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return User
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $shopsAt;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->shopsAt = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Add shopsAt
     *
     * @param \UserStore $shopsAt
     * @return User
     */
    public function addShopsAt(\UserStore $shopsAt)
    {
        $this->shopsAt[] = $shopsAt;

        return $this;
    }

    /**
     * Remove shopsAt
     *
     * @param \UserStore $shopsAt
     */
    public function removeShopsAt(\UserStore $shopsAt)
    {
        $this->shopsAt->removeElement($shopsAt);
    }

    /**
     * Get shopsAt
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getShopsAt()
    {
        return $this->shopsAt;
    }
}

///////////////////////////////////////

use Doctrine\ORM\Mapping as ORM;

/**
 * Store
 */
class Store
{
    /**
     * @var integer
     */
    private $id;

    /**
     * @var string
     */
    private $streetname;

    /**
     * @var string
     */
    private $streetnumber;

    /**
     * @var string
     */
    private $cp;

    /**
     * @var string
     */
    private $lat;

    /**
     * @var string
     */
    private $lng;

    /**
     * @var integer
     */
    private $favorite;

    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $productsAvailable;

    /**
     * @var \Brand
     */
    private $brand;

    /**
     * @var \Neighborhood
     */
    private $neighborhood;

    /**
     * @var \County
     */
    private $county;

    /**
     * @var \City
     */
    private $city;

    /**
     * @var \State
     */
    private $state;

    /**
     * Constructor
     */
    public function __construct()
    {
        $this->productsAvailable = new \Doctrine\Common\Collections\ArrayCollection();
    }

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set streetname
     *
     * @param string $streetname
     * @return Store
     */
    public function setStreetname($streetname)
    {
        $this->streetname = $streetname;

        return $this;
    }

    /**
     * Get streetname
     *
     * @return string 
     */
    public function getStreetname()
    {
        return $this->streetname;
    }

    /**
     * Set streetnumber
     *
     * @param string $streetnumber
     * @return Store
     */
    public function setStreetnumber($streetnumber)
    {
        $this->streetnumber = $streetnumber;

        return $this;
    }

    /**
     * Get streetnumber
     *
     * @return string 
     */
    public function getStreetnumber()
    {
        return $this->streetnumber;
    }

    /**
     * Set cp
     *
     * @param string $cp
     * @return Store
     */
    public function setCp($cp)
    {
        $this->cp = $cp;

        return $this;
    }

    /**
     * Get cp
     *
     * @return string 
     */
    public function getCp()
    {
        return $this->cp;
    }

    /**
     * Set lat
     *
     * @param string $lat
     * @return Store
     */
    public function setLat($lat)
    {
        $this->lat = $lat;

        return $this;
    }

    /**
     * Get lat
     *
     * @return string 
     */
    public function getLat()
    {
        return $this->lat;
    }

    /**
     * Set lng
     *
     * @param string $lng
     * @return Store
     */
    public function setLng($lng)
    {
        $this->lng = $lng;

        return $this;
    }

    /**
     * Get lng
     *
     * @return string 
     */
    public function getLng()
    {
        return $this->lng;
    }

    /**
     * Set favorite
     *
     * @param integer $favorite
     * @return Store
     */
    public function setFavorite($favorite)
    {
        $this->favorite = $favorite;

        return $this;
    }

    /**
     * Get favorite
     *
     * @return integer 
     */
    public function getFavorite()
    {
        return $this->favorite;
    }

    /**
     * Set status
     *
     * @param integer $status
     * @return Store
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return Store
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return Store
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Add productsAvailable
     *
     * @param \ProductStore $productsAvailable
     * @return Store
     */
    public function addProductsAvailable(\ProductStore $productsAvailable)
    {
        $this->productsAvailable[] = $productsAvailable;

        return $this;
    }

    /**
     * Remove productsAvailable
     *
     * @param \ProductStore $productsAvailable
     */
    public function removeProductsAvailable(\ProductStore $productsAvailable)
    {
        $this->productsAvailable->removeElement($productsAvailable);
    }

    /**
     * Get productsAvailable
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getProductsAvailable()
    {
        return $this->productsAvailable;
    }

    /**
     * Set brand
     *
     * @param \Brand $brand
     * @return Store
     */
    public function setBrand(\Brand $brand = null)
    {
        $this->brand = $brand;

        return $this;
    }

    /**
     * Get brand
     *
     * @return \Brand 
     */
    public function getBrand()
    {
        return $this->brand;
    }

    /**
     * Set neighborhood
     *
     * @param \Neighborhood $neighborhood
     * @return Store
     */
    public function setNeighborhood(\Neighborhood $neighborhood = null)
    {
        $this->neighborhood = $neighborhood;

        return $this;
    }

    /**
     * Get neighborhood
     *
     * @return \Neighborhood 
     */
    public function getNeighborhood()
    {
        return $this->neighborhood;
    }

    /**
     * Set county
     *
     * @param \County $county
     * @return Store
     */
    public function setCounty(\County $county = null)
    {
        $this->county = $county;

        return $this;
    }

    /**
     * Get county
     *
     * @return \County 
     */
    public function getCounty()
    {
        return $this->county;
    }

    /**
     * Set city
     *
     * @param \City $city
     * @return Store
     */
    public function setCity(\City $city = null)
    {
        $this->city = $city;

        return $this;
    }

    /**
     * Get city
     *
     * @return \City 
     */
    public function getCity()
    {
        return $this->city;
    }

    /**
     * Set state
     *
     * @param \State $state
     * @return Store
     */
    public function setState(\State $state = null)
    {
        $this->state = $state;

        return $this;
    }

    /**
     * Get state
     *
     * @return \State 
     */
    public function getState()
    {
        return $this->state;
    }
    /**
     * @var \Doctrine\Common\Collections\Collection
     */
    private $shoppers;


    /**
     * Add shoppers
     *
     * @param \UserStore $shoppers
     * @return Store
     */
    public function addShopper(\UserStore $shoppers)
    {
        $this->shoppers[] = $shoppers;

        return $this;
    }

    /**
     * Remove shoppers
     *
     * @param \UserStore $shoppers
     */
    public function removeShopper(\UserStore $shoppers)
    {
        $this->shoppers->removeElement($shoppers);
    }

    /**
     * Get shoppers
     *
     * @return \Doctrine\Common\Collections\Collection 
     */
    public function getShoppers()
    {
        return $this->shoppers;
    }
}


//////////////////////////////////////////////////


use Doctrine\ORM\Mapping as ORM;

/**
 * UserStore
 */
class UserStore
{
    /**
     * @var integer
     */
    private $status;

    /**
     * @var \DateTime
     */
    private $createdAt;

    /**
     * @var \DateTime
     */
    private $updatedAt;

    /**
     * @var \User
     */
    private $user;

    /**
     * @var \Store
     */
    private $store;


    /**
     * Set status
     *
     * @param integer $status
     * @return UserStore
     */
    public function setStatus($status)
    {
        $this->status = $status;

        return $this;
    }

    /**
     * Get status
     *
     * @return integer 
     */
    public function getStatus()
    {
        return $this->status;
    }

    /**
     * Set createdAt
     *
     * @param \DateTime $createdAt
     * @return UserStore
     */
    public function setCreatedAt($createdAt)
    {
        $this->createdAt = $createdAt;

        return $this;
    }

    /**
     * Get createdAt
     *
     * @return \DateTime 
     */
    public function getCreatedAt()
    {
        return $this->createdAt;
    }

    /**
     * Set updatedAt
     *
     * @param \DateTime $updatedAt
     * @return UserStore
     */
    public function setUpdatedAt($updatedAt)
    {
        $this->updatedAt = $updatedAt;

        return $this;
    }

    /**
     * Get updatedAt
     *
     * @return \DateTime 
     */
    public function getUpdatedAt()
    {
        return $this->updatedAt;
    }

    /**
     * Set user
     *
     * @param \User $user
     * @return UserStore
     */
    public function setUser(\User $user)
    {
        $this->user = $user;

        return $this;
    }

    /**
     * Get user
     *
     * @return \User 
     */
    public function getUser()
    {
        return $this->user;
    }

    /**
     * Set store
     *
     * @param \Store $store
     * @return UserStore
     */
    public function setStore(\Store $store)
    {
        $this->store = $store;

        return $this;
    }

    /**
     * Get store
     *
     * @return \Store 
     */
    public function getStore()
    {
        return $this->store;
    }

}
foreach ($User->getShopsAt() as $user_store) {
   echo $user_store->getStatus();
   echo $user_store->getCreate at();
}
$User->getShopsAt()->count()
count($User->getShopsAt()) <-- note I am NOT wrapping it in []

这将把UserStore对象的ArrayCollection转换为UserStore对象的简单数组。

调试的快速提示:尝试
dump($value)而不是
echo$value
。谢谢Tomás。您的评论很有用,dump不起作用,但我遵循您的想法,在PHP文档中找到了var_dump。使用它之后,它显示了一个几乎不可能理解的巨大结构,但是我能够看到关系中使用的所有字段,并且我发现了错误。在我的YML文件中,用户被设置为mappedBy:product,应该是mappedBy:User。再次感谢,抱歉这是
var\u dump($value)当然。dump是我使用的调试工具的自定义函数。不管怎样,我很高兴它对你有帮助。