Update: It's not just username
that's this affects. I even tried renaming the column to foo
in my schema, and still it always returns null
for that column!
My database is in MySQL (InnoDB). I have a users
table, containing the properties ID
, username
, name
, email
, password
. Table has a bunch of users inserted in it.
On the Doctrine side, my AppBundle\Entity\User
class is correctly defined. I can query my users and get a list of them, with all the columns intact -- except for the username
column.
Despite username
being defined in PHP:
/**
* User
*
* @ORM\Table(name="user", uniqueConstraints={@ORM\UniqueConstraint(name="username_UNIQUE", columns={"username"})})
* @ORM\Entity
*/
class User
{
/**
* @var string
*
* @ORM\Column(name="username", type="string", length=45, nullable=false)
*/
private $username;
// ...
/**
* Set username
*
* @param string $username
*
* @return User
*/
public function setUsername($username)
{
$this->username = $username;
return $this;
}
/**
* Get username
*
* @return string
*/
public function getUsername()
{
return $this->username;
}
When I get the entities and dump them, the username field has mysteriously been nulled:
User {#389 ▼
-id: 2
-username: null
-name: "Sam"
-password: XXX
-email: XXX
-oPhone: ""
-mPhone: XXX
-hPhone: ""
-institutions: PersistentCollection {#390 ▶}
}
Even though it definitely exists and is not null on the database:
mysql> SELECT * FROM user WHERE id=2
# ID, username, name, password, email, o_phone, m_phone, h_phone
2, sjw, Sam, XXX, XXX, , XXX,
And trying to access the field via PHP results in it complaining that no such username
field exists, preventing me from doing user auth using this entity.
I'm not using any custom app bundles in Symfony, which is version 2.7.6 (with doctrine2), on PHP 5.4.
I've cleared my caches, made sure I haven't had any Doctrine-generated .yml or .xml models lying around.
I've sanity-checked my database -- using the sqlalchemy Python library and
sqlacodegen
I have a python version of my ORM. That has no problems with theusername
column, results appear as they should, rather than being null or NoneType.I've temporarily disabled the SecurityBundle to see if it was removing the username behind the scenes -- the field is still nulled.
I've pored over the Symfony docs...
Nope, out of ideas. What is Symfony doing behind the scenes?
public $username;
– Daleusername
not being a field (even when it was set to public). That was yesterday's work, however.. :p – Owain Jones