protected function belongs_to($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_associated_models_table = null, $connection_name = null)
        {
            $associated_table_name = self::_getTableName(self::$auto_prefix_models . $associated_class_name);
            $foreign_key_name = self::_buildForeignKeyName($foreign_key_name, $associated_table_name);
            $associated_object_id = $this->$foreign_key_name;

            $desired_record = null;

            if( is_null($foreign_key_name_in_associated_models_table) ) {
                //"{$associated_table_name}.primary_key = {$associated_object_id}"
                //NOTE: primary_key is a placeholder for the actual primary key column's name
                //in $associated_table_name
                $desired_record = self::factory($associated_class_name, $connection_name)->where_id_is($associated_object_id);
            } else {
                //"{$associated_table_name}.{$foreign_key_name_in_associated_models_table} = {$associated_object_id}"
                $desired_record = self::factory($associated_class_name, $connection_name)->where($foreign_key_name_in_associated_models_table, $associated_object_id);
            }

            return $desired_record;
        }
protected function belongs_to($associated_class_name, $foreign_key_name = null, $foreign_key_name_in_associated_models_table = null, $connection_name = null)
        {
            $associated_table_name = self::_getTableName(self::$auto_prefix_models . $associated_class_name);
            $foreign_key_name = self::_buildForeignKeyName($foreign_key_name, $associated_table_name);
            $associated_object_id = $this->$foreign_key_name;

            $desired_record = null;

            if( is_null($foreign_key_name_in_associated_models_table) ) {
                //"{$associated_table_name}.primary_key = {$associated_object_id}"
                //NOTE: primary_key is a placeholder for the actual primary key column's name
                //in $associated_table_name
                $desired_record = self::factory($associated_class_name, $connection_name)->where_id_is($associated_object_id);
            } else {
                //"{$associated_table_name}.{$foreign_key_name_in_associated_models_table} = {$associated_object_id}"
                $desired_record = self::factory($associated_class_name, $connection_name)->where($foreign_key_name_in_associated_models_table, $associated_object_id);
            }

            return $desired_record;
        }
protected function belongs_to ( $ associated_class_name , $ foreign_key_name = null , $ foreign_key_name_in_associated_models_table = null , $ connection_name = null ) { $ associated_table_name = self :: _getTableName ( self :: $ auto_prefix_models . $ associated_class_name ) ; $ foreign_key_name = self :: _buildForeignKeyName ( $ foreign_key_name , $ associated_table_name ) ; $ associated_object_id = $ this -> $ foreign_key_name ; $ desired_record = null ; if ( is_null ( $ foreign_key_name_in_associated_models_table ) ) { //"{$associated_table_name}.primary_key = {$associated_object_id}" //NOTE: primary_key is a placeholder for the actual primary key column's name //in $associated_table_name $ desired_record = self :: factory ( $ associated_class_name , $ connection_name ) -> where_id_is ( $ associated_object_id ) ; } else { //"{$associated_table_name}.{$foreign_key_name_in_associated_models_table} = {$associated_object_id}" $ desired_record = self :: factory ( $ associated_class_name , $ connection_name ) -> where ( $ foreign_key_name_in_associated_models_table , $ associated_object_id ) ; } return $ desired_record ; }
Helper method to manage one-to-one and one-to-many relations where
the foreign key is on the base table.

@param  string      $associated_class_name
@param  null|string $foreign_key_name
@param  null|string $foreign_key_name_in_associated_models_table
@param  null|string $connection_name
@return $this|null
Helper method to manage one - to - one and one - to - many relations where the foreign key is on the base table .