メインコンテンツまでスキップ
Version: Fegg 5.x(開発版)

Model::join

Set Join Parameter

Description​

public self Model::join( string|array $table, [ string $type = 'INNER', string $on = null, mixed $data = [] ] )

Joins another table. $table is a table name, or array('table', 'alias'); both must be plain names, or InvalidArgumentException is thrown. $on takes ? placeholders and $data works as in where.

The automatic valid = 1 and visible conditions only apply to the model's own table. Add them to $on for the joined table when you need them.

Arguments​

NameData typeDefaultRemarks
$tablestring/arrayTable name, or array('table', 'alias')
$typestring'INNER''INNER', 'LEFT' or 'RIGHT' (anything else: INNER)
$onstringnullON condition with ? placeholders
$datamixed[]Values for the ON placeholders

Example​

Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));

// Select cms_news.*, f.org_name
// From "cms_news"
// LEFT JOIN "cms_file" AS "f" ON f.file_id = cms_news.file_id AND f.valid = 1
// Where ...
$records = $model
->select('cms_news.*, f.org_name')
->join(array('cms_file', 'f'), 'LEFT', 'f.file_id = cms_news.file_id AND f.valid = ?', 1)
->find();