1
トークンでユーザーを検索したい私は1対1の関係を持っています。私の教義の設定ファイル:symfony3検索でリレーション
AppBundle\UserEntity:
type: entity
table: null
repositoryClass: AppBundle\Repository\UserEntityRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
username:
type: string
length: 255
unique: true
password:
type: string
length: 255
nullable: true
salt:
type: string
length: 255
unique: true
email:
type: string
length: '100'
lifecycleCallbacks: { }
oneToMany:
token:
targetEntity: TokenEntity
mappedBy: user
fetch: EAGER
AppBundle\TokenEntity:
type: entity
table: null
repositoryClass: AppBundle\Repository\TokenEntityRepository
id:
id:
type: integer
id: true
generator:
strategy: AUTO
fields:
value:
type: string
length: 255
unique: true
lifecycleCallbacks: { }
manyToOne:
user:
targetEntity: UserEntity
inversedBy: token
joinColumns:
user_id:
referencedColumnName: id
私はトークンによって、検索ユーザーをしよう:
UserEntityRepository.php
<?php
class UserEntityRepository extends EntityRepository
{
public function loadUserByToken(string $token)
{
$repository = $this->_em->getRepository('AppBundle:UserEntity');
$user = $repository->findOneBy(['token'=>1]);
return $user;
}
}
symfonyのスロー例外:
あなたは関連フィールドを検索することはできません 'AppBundle \ Entity \ UserEntity#token'です。 は関連しています。 Findメソッドは、サイド・アソシエーションを所有する場合にのみ機能します。
何が問題なのですか。どのようにこの関係を修復する?ユーザーにはトークンがほとんどありません。
私を助けることができますか?
これは動作します! via - > findOneByはうまくいくはずだと思っていましたが、この解決法は問題ありません。ありがとう! – Matrix12