本文整理汇总了PHP中ORM::foreign_key方法的典型用法代码示例。如果您正苦于以下问题:PHP ORM::foreign_key方法的具体用法?PHP ORM::foreign_key怎么用?PHP ORM::foreign_key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ORM
的用法示例。
在下文中一共展示了ORM::foreign_key方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load_relations
/**
* Return an array of all the primary keys of the related table.
*
* @param string table name
* @param object ORM model to find relations of
* @return array
*/
protected function load_relations($table, ORM $model)
{
// Save the current query chain (otherwise the next call will clash)
$this->db->push();
$query = $this->db->select($model->foreign_key(NULL) . ' AS id')->from($table)->where($this->foreign_key(NULL, $table), $this->object[$this->primary_key])->get()->result(TRUE);
$this->db->pop();
$relations = array();
foreach ($query as $row) {
$relations[] = $row->id;
}
return $relations;
}
示例2: load_relations
/**
* Return an array of all the primary keys of the related table.
*
* @param string table name
* @param object ORM model to find relations of
* @return array
*/
protected function load_relations($table, ORM $model)
{
$result = db::select(array('id' => $model->foreign_key($table)))->from($table)->where($this->foreign_key($table, $table), '=', $this->primary_key_value)->execute($this->db)->as_object();
$relations = array();
foreach ($result as $row) {
$relations[] = $row->id;
}
return $relations;
}
示例3: load_relations
/**
* Return an array of all the primary keys of the related table.
*
* @param string table name
* @param object ORM model to find relations of
* @return array
*/
protected function load_relations($table, ORM $model)
{
$query = $this->db->select($model->foreign_key(NULL) . ' AS id')->from($table)->where($this->foreign_key(NULL, $table), $this->object[$this->primary_key])->get()->result(TRUE);
$relations = array();
foreach ($query as $row) {
$relations[] = $row->id;
}
return $relations;
}
示例4: has
/**
* Tests if this object has a relationship to a different model.
*
* @param object related ORM model
* @return boolean
*/
public function has(ORM $model)
{
if (!$this->loaded) {
return FALSE;
}
if (($join_table = array_search(inflector::plural($model->object_name), $this->has_and_belongs_to_many)) === FALSE) {
return FALSE;
}
if (is_int($join_table)) {
// No "through" table, load the default JOIN table
$join_table = $model->join_table($this->table_name);
}
if ($model->loaded) {
// Select only objects of a specific id
$this->db->where($model->foreign_key(NULL, $join_table), $model->primary_key_value);
}
// Return the number of rows that exist
return $this->db->where($this->foreign_key(NULL, $join_table), $this->object[$this->primary_key])->count_records($join_table);
}