我使用Symfony 3,并希望将实体User
映射为具有许多BitcoinWallet
我的AppBundle'Entity'User.php
看起来像这样:
<?php
namespace AppBundle'Entity;
use Doctrine'ORM'Mapping as ORM;
use FOS'UserBundle'Model'User as BaseUser;
use Gedmo'Mapping'Annotation as Gedmo;
use Symfony'Component'Validator'Constraints as Assert;
/**
* @ORM'Entity
* @ORM'Table(name="user")
*/
class User extends BaseUser
{
/**
* @ORM'Id
* @ORM'Column(type="integer")
* @ORM'GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @var string
* @ORM'Column(type="string", length=255, nullable=true)
*/
protected $firstName;
/**
* @var string
* @ORM'Column(type="string", length=255, nullable=true)
*/
protected $lastName;
/**
* @ORM'Column(type="string", length=255, nullable=true)
* @Assert'File(maxSize="2048k")
* @Assert'Image(mimeTypesMessage="Please upload a valid image.")
*/
protected $profilePicture;
/**
* @Assert'Email(
* message = "The email '{{ value }}' is not a valid email.",
* checkMX = true
* )
*/
protected $email;
protected $emailCanonical;
/**
* @ORM'ManyToOne(targetEntity="BitcoinBundle'Entity'BitcoinWallet")
* @ORM'JoinColumn(name="bitcoin_wallet", referencedColumnName="id")
*/
protected $bitcoinWallet;
/**
* @var 'DateTime $created
*
* @Gedmo'Timestampable(on="create")
* @ORM'Column(type="datetime")
*/
private $created;
/**
* @var 'DateTime $updated
*
* @Gedmo'Timestampable(on="update")
* @ORM'Column(type="datetime")
*/
private $updated;
我的BitcoinBundle'Entity'BitcoinWallet
如下:
<?php
namespace BitcoinBundle'Entity;
use Doctrine'ORM'Mapping as ORM;
/**
* @ORM'Entity(repositoryClass="BitcoinBundle'Entity'BitcoinWalletRepository")
* @ORM'Table(name="bitcoin_wallet")
* @ORM'HasLifecycleCallbacks
*/
class BitcoinWallet
{
/**
* in use = The address is being used for some reason
* available = the address is free
*/
const STATE_IN_USE = 0;
const STATE_AVAILABLE = 1;
/**
* @ORM'Id
* @ORM'Column(type="integer")
* @ORM'GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM'Column
* @ORM'GeneratedValue(strategy="NONE")
* @ORM'Column(type="string", length=34, unique=true)
*/
private $address;
/**
* @ORM'Column(name="state", type="smallint")
*/
private $state;
/**
* @ORM'Column(name="balance", type="decimal", precision=16, scale=8)
*/
private $balance = 0;
/**
* @ORM'Column(name="updated_at", type="datetime")
*/
private $updated_at;
我运行php bin/console doctrine:schema:update --force
数据库更新成功后,但现在我得到这个消息:
在'AppBundle'Entity'User# BitcoinWallet '中找不到目标实体BitcoinBundle'Entity'BitcoinWallet .
看起来实体声明不正确。
在BitcoinBundle'Entity'BitcoinWallet
中应该是ManyToOne
语句:
/**
* @ORM'Id
* @ORM'Column(type="integer")
* @ORM'GeneratedValue(strategy="AUTO")
* @ORM'ManyToOne(targetEntity="UserBundle'Entity'User", inversedBy="bitcoin_wallet")
*/
protected $id;
, AppBundle'Entity'User.php
中的ManyToOne
语句是错误的。