-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用leftJoin时, Model的columnMap不工作 #12715
Comments
@dreamsxin any idea what's a problem here? |
@Jurigag The following two code returns difference results: $query = $modelsManager->createBuilder()
->andFrom(Order::class, 'o')
->leftJoin(User::class, 'o.clientId=u.uid', 'u')
->columns('u.*')->getQuery();
$users = $query->execute(); Two: $query = $modelsManager->createBuilder()
->andFrom(Order::class, 'o')
->addFrom(User::class, 'u')->andWhere('o.clientId=u.uid')
->columns('u.*')->getQuery();
$users = $query->execute(); |
Use |
检查过结果集的,有多条记录,但都不正确。 |
Left join右表不一定要有数据,所以你可以互换两表位置,你可以直接在数据库里sql查下 |
dreamsxin, 你好, 在数据库sql查右表有数据, 我仔细检查过了. |
@sprufu |
dreamsxin, 你好, 这确实有问题, 关键的地方是自定义了 MySQL的数据库: -- 用的是MySQL
CREATE TABLE `order` (
`id` INT NOT NULL,
`clientId` INT NOT NULL,
PRIMARY KEY (`id`)
);
CREATE TABLE `user` (
`user_id` INT(11) NOT NULL,
`user_name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`user_id`)
);
INSERT INTO `test`.`user` (`user_id`, `user_name`) VALUES (1, 'sprufu');
INSERT INTO `test`.`order` (`id`, `clientId`) VALUES (1, 1); php相关代码: class User extends \Phalcon\Mvc\Model {
protected $name;
protected $uid;
public function getName() {
return $this->name;
}
public function columnMap() {
return [
'user_name' => 'name',
'user_id' => 'uid'
];
}
}
class Order extends \Phalcon\Mvc\Model {
protected $id;
protected $clientId;
}
class UserTest extends \PHPUnit_Framework_TestCase {
private $di;
protected function setUp() {
$di = new \Phalcon\Di\FactoryDefault();
$di->setShared('db', function () {
$connection = new \Phalcon\Db\Adapter\Pdo\Mysql([
'host' => '127.0.0.1',
'port' => 3306,
'username' => 'test_user',
'password' => 'test_12345',
'dbname' => 'test',
'charset' => 'UTF8'
]);
return $connection;
});
$this->di = $di;
}
public function testGetNameReturnNullValue() {
$modelsManager = $this->di->get('modelsManager');
$query = $modelsManager->createBuilder()
->addFrom(Order::class, 'o')
->leftJoin(User::class, 'o.clientId=u.uid', 'u')
->columns('u.*')
->getQuery();
$users = $query->execute();
self::assertGreaterThanOrEqual(1, count($users)); // ok
$user = $users[0];
self::assertNotNull($user->getName()); // fail
}
} |
我一直以为数据不对,原来是columnmap错了,已经找到问题。 |
See #12719 你可以测试这个分支 |
Fixed in the |
两位高手呀 |
Hi, 在使用php7.0 + phalcon3.0.4时model的属性为null, 以下是使用前提:
Details
php --ri phalcon
)php -v
)The text was updated successfully, but these errors were encountered: