User.php
publict function content()
{
$this->join('content', 'content.user_id', 'user.user_id')
}
とすると、発行されるSQLは
SELECT *
from user
inner join content
on
content.user_id = user.user_id
where user.deleted_at is NULL
となる。多分(間違っていたらすみません)
ここでcontentの主キ-も(content_id)取得したいとする。
そこでselect()の出番
次のようにする
$this->join('content', 'content.user_id', 'user.user_id')
->select('user.*', 'content.content_id')
すると
SELECT user.*,
content.content_id
from user
inner join content
on
content.user_id = user.user_id
where user.deleted_at is NULL
簡単に結合先のカラム取得できた。