gpt4 book ai didi

php - 如何告诉 Paris/ORM 哪个表用于模型?

转载 作者:行者123 更新时间:2023-11-29 06:35:30 24 4
gpt4 key购买 nike

我刚刚在使用 Idiorm/Paris 的应用程序中添加了一些连接,我发现当我通过 Model::factory() 进行搜索时,返回的对象是从连接对象获取 ID,而不是“父对象” ' 对象。

我如何告诉 Paris 哪个表别名应该构成模型?

我是在搜索上下文中这样做的,所以我不认为我可以使用 has_many() 但我很乐意犯错!

示例代码:

// Find a booking with a join
$query = Model::factory('Booking');
$query->where('booking.id', '2282');
$query->join(
'customer',
array('booking.id', '=', 'customer.booking_id'),
'customer'
);
$bookingWithJoin = $query->find_one();

// Find the same booking, without a join
$query = Model::factory('Booking');
$query->where('id', '2282');
$bookingWithoutJoin = $query->find_one();

// The booking with a join gets the ID of the customer it's joined with
echo $bookingWithJoin->id .' != '. $bookingWithoutJoin->id;

最佳答案

我发现答案是 $query->select('booking.*');

是否等同于

SELECT booking.* FROM bookings JOIN customer on booking.customer_id = customer.id

所以返回的结果不会包含customer.*字段。

关于php - 如何告诉 Paris/ORM 哪个表用于模型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25104614/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com