【发布时间】:2014-08-03 12:26:12
【问题描述】:
我刚刚在我的使用 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;
【问题讨论】:
-
公共静态 $_table = 'my_user_table';在此处记录:paris.readthedocs.org/en/latest/models.html#model-classes