本文整理汇总了PHP中think\Model::alias方法的典型用法代码示例。如果您正苦于以下问题:PHP Model::alias方法的具体用法?PHP Model::alias怎么用?PHP Model::alias使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类think\Model
的用法示例。
在下文中一共展示了Model::alias方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testJoin
public function testJoin()
{
$config = $this->getConfig();
$user_model = new Model('user', $config);
$join = [[['order o', 'tp_'], 'u.id=o.user_id'], [['user_address' => 'a'], 'u.id=a.user_id']];
$result = $user_model->alias('u')->join($join)->field('u.username,a.consignee,o.amount')->select();
$data = ['username' => 'test', 'consignee' => '张三', 'amount' => '200'];
$this->assertEquals($data, $result[0]);
$result = $user_model->alias('u')->join('__USER_ADDRESS__ a', 'u.id=a.user_id', 'left')->field('u.username,a.consignee')->select();
$data = ['username' => 'test', 'consignee' => '张三'];
$this->assertEquals($data, $result[0]);
$result = $user_model->alias('u')->join('role_user ru', 'u.id=ru.user_id', 'left')->field('u.username,ru.role_id')->select();
$data = ['username' => 'test', 'role_id' => '1'];
$this->assertEquals($data, $result[0]);
$order_model = new Model('order', $config);
$subsql = $order_model->limit(1)->buildSql();
$result = $user_model->alias('u')->join($subsql . ' o', 'u.id=o.user_id', 'left')->field('u.username,o.amount')->select();
$data = ['username' => 'test', 'amount' => '200'];
$this->assertEquals($data, $result[0]);
// 兼容_join方法
$result = $user_model->alias('u')->join('__USER_ADDRESS__ a on u.id=a.user_id', 'left')->field('u.username,a.consignee')->select();
$data = ['username' => 'test', 'consignee' => '张三'];
$this->assertEquals($data, $result[0]);
}