所以我的两个实体都有 ID 属性,但我收到有关下面描述的两个表的上述 ID 的验证错误。我在SO上看到了此问题的其他一些示例,并遵循了他们的解决方案,但仍未通过此验证错误。
我也遵循了教义文档,我想我只是错过了一些东西。我只与Symfony/Doctrine合作了几个月,所以也许我错过了一个概念。
我跑php bin/console doctrine:schema:validate
[Mapping] FAIL - The entity-class 'FacetCoreBundleEntityFacetUser' mapping is invalid:
* The referenced column name 'id' has to be a primary key column on the target entity class 'FacetCoreBundleEntityFacetUser'.
* The referenced column name 'id' has to be a primary key column on the target entity class 'FacetCoreBundleEntityFacetRole'.
[Database] OK - The database schema is in sync with the mapping files.
好的,我的分面用户实体有 ID 列,它是一个主键,与分面角色实体相同。
分面用户.php
/**
* @ORMEntity()
* @ORMTable(name="FACET_USER")
*/
class FacetUser implements LdapUserInterface, UserInterface
{
/**
* @var integer
*
* @ORMId
* @ORMGeneratedValue(strategy="AUTO")
* @ORMColumn(name="ID", type="integer")
*/
private $id;
/**
* @var string
*
* @ORMColumn(name="LDAP_GUID", type="string", length=100, unique=true)
* LdapAttribute objectguid
*/
private $ldapGuid;
/**
* @var string
*
* @ORMColumn(name="USERNAME", type="string", length=20)
* LdapAttribute samaccountname
*/
private $username;
/**
* @var string
*
* @ORMColumn(name="FIRST_NAME", type="string", length=100)
* LdapAttribute givenname
*/
private $firstName;
/**
* @var string
*
* @ORMColumn(name="LAST_NAME",type="string", length=100)
* LdapAttribute sn
*/
private $lastName;
/**
* @var string
*
* @ORMColumn(name="DISPLAY_NAME",type="string", length=255)
* LdapAttribute displayname
*/
private $displayName;
/**
* @var string
*
* @ORMColumn(name="TITLE",type="string", length=255)
* LdapAttribute title
*/
private $title;
/**
* @var string
*
* @ORMColumn(name="DEPARTMENT",type="string", length=100)
* LdapAttribute department
*/
private $department;
/**
* @var integer
*
* @ORMColumn(name="EMPLOYEE_ID",type="integer", length=10)
* LdapAttribute employeeid
*/
private $employeeId;
/**
* @var string
*
* @ORMColumn(name="MANAGER_USERNAME",type="string", length=7, nullable=true)
*/
private $managerUsername;
/**
* @var string
*
* @ORMColumn(name="MANAGER_DISPLAY_NAME",type="string", length=255, nullable=true)
*/
private $managerDisplayName;
/**
* @var string
*
* @ORMColumn(name="MANAGER_LDAP_GUID",type="string", length=100, nullable=true)
*/
private $managerLdapGuid;
/**
* @var integer
*
* @ORMColumn(name="MANAGER_EMPLOYEE_ID",type="integer", length=7, nullable=true)
*/
private $managerEmployeeId;
/**
* @var string
*
* @ORMColumn(name="EMAIL",type="string", nullable=true)
* LdapAttribute mail
*/
private $email;
/**
* @var string
*
* @ORMColumn(name="MOBILE",type="string", nullable=true)
* LdapAttribute mobile
*/
private $mobile;
/**
* @var array
*
* @ORMColumn(name="LDAP_MEMBERSHIPS",type="array", nullable=true)
* LdapAttribute memberof
*/
private $ldapMemberships = [];
/**
*
* User can have many roles
* @var array
*
* @ORMManyToMany(targetEntity="FacetCoreBundleEntityFacetRole")
* @ORMJoinTable(name="USER_ROLES",
* joinColumns={@ORMJoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORMJoinColumn(name="role_id", referencedColumnName="id")}
* )
*
*/
private $roles;
public function __construct()
{
$this->roles = new ArrayCollection();
}
....
分面角色.php
/**
* FacetRole
*
* @ORMTable(name="FACET_ROLE")
* @ORMEntity
*/
class FacetRole
{
/**
* @var integer
*
* @ORMColumn(name="ID", type="integer", nullable=false)
* @ORMId
* @ORMGeneratedValue(strategy="SEQUENCE")
*/
private $id;
/**
* @var string
*
* @AssertNotBlank()
* @AssertLength(
* min = 9,
* max = 100,
* minMessage = "Role name must be at least {{ limit }} characters long",
* maxMessage = "Role name cannot be longer than {{ limit }} characters"
* )
* @ORMColumn(name="ROLE_NAME", type="string", length=255, nullable=false, unique=true)
*
*/
private $roleName;
/**
* @var string
*
* @AssertNotBlank()
* @AssertChoice({"Y","N"})
*
* @ORMColumn(name="GRANTABLE", type="string", length=1, nullable=false)
*/
private $grantable;
/**
* @var DateTime
*
* @ORMColumn(name="CREATED_ON", type="date", nullable=false)
*/
private $createdOn;
/**
* @var string
*
* @AssertNotBlank()
* @AssertLength(
* min="10",
* max="255",
* minMessage="Description needs to be at least {{ limit }} characters long.",
* maxMessage="Description needs to be less then {{ limit }} characters long."
* )
*
* @ORMColumn(name="DESCRIPTION", type="string", length=255, nullable=true)
*/
private $description;
/**
* @var FacetUser
*
* @ORMManyToOne(targetEntity="FacetUser")
* @ORMJoinColumns({
* @ORMJoinColumn(name="CREATED_BY", referencedColumnName="ID", nullable=false)
* })
*/
private $createdBy;
....
这将创建存储已授予用户的角色的USER_ROLES表。
根据格雷格的评论,请务必检查字符大小写!请参阅原则可移植性文档的第 3 个项目符号
列键的区分大小写在所有数据库中的处理方式不同,甚至取决于标识符引用与否。您要么需要了解所有规则,要么仅将案例修复为小写/大写。