Yoast\WP\Lib
Model::has_one_or_many() protected Yoast 1.0
Internal method to construct the queries for both the has_one and has_many methods. These two types of association are identical; the only difference is whether find_one or find_many is used to complete the method chain.
{} Это метод класса: Model{}
Хуков нет.
Возвращает
ORM
. Instance of the ORM.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->has_one_or_many( $associated_class_name, $foreign_key_name, $foreign_key_name_in_current_models_table );
- $associated_class_name(строка) (обязательный)
- The associated class name.
- $foreign_key_name(null/строка)
- The foreign key name in the associated table.
- $foreign_key_name_in_current_models_table(null/строка)
- The foreign key in the current models table.
Код Model::has_one_or_many() Model::has one or many Yoast 16.1.1
protected function has_one_or_many( $associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null ) {
$base_table_name = static::get_table_name_for_class( \get_class( $this ) );
$foreign_key_name = static::build_foreign_key_name( $foreign_key_name, $base_table_name );
/*
* Value of foreign_table.{$foreign_key_name} we're looking for. Where foreign_table is the actual
* database table in the associated model.
*/
if ( $foreign_key_name_in_current_models_table === null ) {
// Matches foreign_table.{$foreign_key_name} with the value of "{$this->table}.{$this->id()}".
$where_value = $this->id();
}
else {
// Matches foreign_table.{$foreign_key_name} with "{$this->table}.{$foreign_key_name_in_current_models_table}".
$where_value = $this->{$foreign_key_name_in_current_models_table};
}
return static::factory( $associated_class_name )->where( $foreign_key_name, $where_value );
}