Model::_has_one_or_many PHP Method

_has_one_or_many() protected method

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.
protected _has_one_or_many ( string $associated_class_name, null | string $foreign_key_name = null, null | string $foreign_key_name_in_current_models_table = null, null | string $connection_name = null ) : ORMWrapper
$associated_class_name string
$foreign_key_name null | string
$foreign_key_name_in_current_models_table null | string
$connection_name null | string
return ORMWrapper
    protected function _has_one_or_many($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_current_models_table = null, $connection_name = null)
    {
        $base_table_name = self::_get_table_name(get_class($this));
        $foreign_key_name = self::_build_foreign_key_name($foreign_key_name, $base_table_name);
        $where_value = '';
        //Value of foreign_table.{$foreign_key_name} we're
        //looking for. Where foreign_table is the actual
        //database table in the associated model.
        if (is_null($foreign_key_name_in_current_models_table)) {
            //Match foreign_table.{$foreign_key_name} with the value of
            //{$this->_table}.{$this->id()}
            $where_value = $this->id();
        } else {
            //Match foreign_table.{$foreign_key_name} with the value of
            //{$this->_table}.{$foreign_key_name_in_current_models_table}
            $where_value = $this->{$foreign_key_name_in_current_models_table};
        }
        return self::factory($associated_class_name, $connection_name)->where($foreign_key_name, $where_value);
    }