【问题标题】:How to tell Paris/ORM which table to use for the Model?如何告诉 Paris/ORM 哪个表用于模型?
【发布时间】: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;

【问题讨论】:

标签: php mysql sql idiorm


【解决方案1】:

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

的等价物吗

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-06-20
    • 2010-09-27
    • 2020-10-13
    • 2017-03-23
    • 2023-03-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多