我刚刚在使用 Idiorm/Paris 的应用程序中添加了一些连接,我发现当我通过 Model::factory() 搜索时,返回的对象是从连接对象获取 ID,而不是从“父”对象获取 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;