我有學說2.1實體:Doctrine2不選擇所有的實體領域
/**
* @Entity(repositoryClass="Varlab\Model\Repository\UserRepository")
* @Table(name="user")
*/
class User
{
/**
* @Id @Column(name="id",type="integer")
* @GeneratedValue(strategy="AUTO")
*
* @var integer
*/
protected $_id;
/**
* @Column(name="username",type="string",nullable=false,length=50,unique=true)
* @var string
*/
protected $_username;
/**
* User password
*
* @Column(name="passwd",type="string",nullable=false,length=50)
* @var string
*/
protected $_password;
/**
* @ManyToOne(targetEntity="Role")
* @JoinColumn(name="role_id", referencedColumnName="id")
*
* @var Role
*/
protected $_role;
/**
* @ManyToOne(targetEntity="UserStatus")
* @JoinColumn(name="status_id", referencedColumnName="id")
*
* @var UserStatus
*/
protected $_status;
/**
* @Column(name="address",type="string",nullable=false,length=100)
* @var string
*/
protected $_address;
/**
* @Column(name="description",type="text",nullable=true)
* @var string
*/
protected $_description;
/**
* @Column(name="firstname",type="string",nullable=false,length=50)
* @var string
*/
protected $_firstname;
/**
* @Column(name="lastname",type="string",nullable=false,length=50)
* @var string
*/
protected $_lastname;
/**
* @Column(name="patronymic",type="string",nullable=false,length=50)
* @var string
*/
protected $_patronymic;
/**
* @Column(name="phone",type="string",nullable=false,length=20)
* @var string
*/
protected $_phone;
// ... some get/set methods here
}
我嘗試使用此代碼更新用戶實體:
$item = $em->find('User', 1);
$item->setFirstname('some name');
$em->merge($item);
$em->flush();
但沒有什麼是發生在數據庫名字字段。我看着主義SQL日誌,看到學說不獲取所有領域:
SELECT t0.id AS id1, t0.username AS username2, t0.passwd AS passwd3, t0.role_id AS role_id4, t0.status_id AS status_id5 FROM user t0 WHERE t0.id = ?
如果我試圖改變用戶名,這是所有的權利和外地在數據庫中更改。從原則日誌
$item = $em->find('User', 1);
$item->setUsername('some user');
$em->merge($item);
$em->flush();
更新SQL:
UPDATE user SET username = ? WHERE id = ?
我怎樣才能獲取我的實體的各個領域?爲什麼這樣?
你能展示你用來更新「用戶名」的代碼嗎?第一遍我無法檢測到問題。 – cantera
我添加了更改數據庫中用戶名字段的代碼 –