簡體   English   中英

如何告訴Paris / ORM該模型使用哪個表?

[英]How to tell Paris/ORM which table to use for the Model?

我剛剛在使用Idiorm / Paris的應用程序中添加了一些Joins,我發現當我通過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;

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

是否等同於

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

因此,返回的結果將不包含customer.*字段。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM