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);
}