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

时间:2014-08-03 12:26:13

标签: php mysql sql idiorm

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

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

我在搜索环境中这样做,所以我不认为我可以使用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;

1 个答案:

答案 0 :(得分:2)

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

相当于

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

因此,返回的结果不会包含customer.*个字段。