【发布时间】:2016-07-03 00:53:22
【问题描述】:
我有一个这样的查询:
$phsql = "
SELECT s.id AS siteId, s.name
FROM site s
INNER JOIN profiles p ON s.id = p.siteId
INNER JOIN users_profiles up ON up.profilesId = p.id
AND p.name = 'admin'
AND up.usersId = 2
";
我在模型方法中转换如下:
$sites = Site::query()
->innerJoin('Profiles', 'Sites.id = Profiles.siteId')
->innerJoin('UsersProfiles', 'UsersProfiles.profilesId = Profiles.id')
->andWhere('Profiles.name = name')
->andWhere('UsersProfiles.usersId = :usersId:', ['userId' => $admin_id])->execute();
运行时会报错:
无法加载模型配置文件
请注意我在 Site 模型中运行它。
更新
我试过了:
$sites = $this->modelsManager->createBuilder()
->from('myApp\Models\Site')
->innerJoin('myApp\Models\Profiles','myApp\Models\Site.id = myApp\Models\Profiles.siteId')
->andWhere("myApp\Models\Profiles.name = 'admin' ")
->where("myApp\Models\UsersProfiles.profilesId = 2")
->getQuery()
->execute();
现在它给出了错误:
未知模型或别名'myApp\Models\UsersProfiles' (11),准备时:SELECT [myApp\Models\Site].* FROM [myApp\Models\Site] INNER JOIN [myApp\Models\Profiles] ON myApp \Models\Site.id = myApp\Models\Profiles.siteId WHERE myApp\Models\UsersProfiles.profilesId = 2
【问题讨论】:
-
你在使用命名空间吗?你为什么要两次
->execute();?这是复制粘贴错误吗? -
@Timothy 复制/粘贴错误
标签: php phalcon phalcon-orm