Php 如何使用外键关系从数据库检索列?
我有一个user表,它存储了他的所有信息,我还通过schema.yml创建了一个名为user\u education的表。[uid此表中的列指的是user表的uid]。模型类是使用Symfony创建的。我能够访问user表的所有列。例如sf_user->getUser()->getUsername() 用户模型类还有一个方法,getUserEducations()。我需要访问user_education table中名为coursename的列,但无法访问。目前,我正在尝试[sf_user->getUser()->getUserEducations()->getCoursename();]但是我得到了整个记录数组。我无法通过该数组检索单个列 如何检索它?您可以通过以下方式进行检索:Php 如何使用外键关系从数据库检索列?,php,symfony1,foreign-keys,foreign-key-relationship,propel,Php,Symfony1,Foreign Keys,Foreign Key Relationship,Propel,我有一个user表,它存储了他的所有信息,我还通过schema.yml创建了一个名为user\u education的表。[uid此表中的列指的是user表的uid]。模型类是使用Symfony创建的。我能够访问user表的所有列。例如sf_user->getUser()->getUsername() 用户模型类还有一个方法,getUserEducations()。我需要访问user_education table中名为coursename的列,但无法访问。目前,我正在尝试[sf_user->g
// get the first tuple
$sf_user->getUser()->getUserEducations()->getFirst()->getCoursename();
或
正确的方法(如果用户受过很多教育)是在实例之间迭代:
foreach($sf_user->getUser()->getUserEducations() as $education){
//do something with like
echo $education->getCoursename();
}
foreach($sf_user->getUser()->getUserEducations() as $education){
//do something with like
echo $education->getCoursename();
}