// GetComments gets the 'Comments' relationship for provided input 'model'.
GetComments gets the 'Comments' relationship for provided input 'model'.
// GetComments gets the ' Comments ' relationship for provided input ' model ' .
func (p *_Posts) GetComments(ctx context.Context, db database.DB, model *Post, relationFieldset ...string) ([]*Comment, error) {
	if model == nil {
		return nil, errors.Wrap(query.ErrNoModels, "provided nil model")
	}
	if model.IsPrimaryKeyZero() {
		return nil, errors.Wrap(mapping.ErrFieldValue, "model's: 'Post' primary key value has zero value")
	}
	relationField, err := p.Model.RelationByIndex(6)
	if err != nil {
		return nil, err
	}
	var fields []*mapping.StructField
	relationModel := relationField.Relationship().RelatedModelStruct()
	if len(relationFieldset) == 0 {
		fields = relationModel.Fields()
	} else {
		for _, field := range relationFieldset {
			sField, ok := relationModel.FieldByName(field)
			if !ok {
				return nil, errors.Wrapf(mapping.ErrInvalidModelField, "no field: '%s' found for the model: 'Comment'", field)
			}
			fields = append(fields, sField)
		}
	}
	relations, err := db.GetRelations(ctx, p.Model, []mapping.Model{model}, relationField, fields...)
	if err != nil {
		return nil, err
	}
	if len(relations) == 0 {
		return []*Comment{}, nil
	}
	result := make([]*Comment, len(relations))
	for i, relation := range relations {
		result[i] = relation.(*Comment)
	}
	return result, nil
}
func ( p * _Posts ) GetComments ( ctx context . Context , db database . DB , model * Post , relationFieldset ... string ) ( [ ] * Comment , error ) { if model == nil { return nil , errors . Wrap ( query . ErrNoModels , " " ) } if model . IsPrimaryKeyZero ( ) { return nil , errors . Wrap ( mapping . ErrFieldValue , " " ) } relationField , err := p . Model . RelationByIndex ( 6 ) if err != nil { return nil , err } var fields [ ] * mapping . StructField relationModel := relationField . Relationship ( ) . RelatedModelStruct ( ) if len ( relationFieldset ) == 0 { fields = relationModel . Fields ( ) } else { for _ , field := range relationFieldset { sField , ok := relationModel . FieldByName ( field ) if ! ok { return nil , errors . Wrapf ( mapping . ErrInvalidModelField , " " , field ) } fields = append ( fields , sField ) } } relations , err := db . GetRelations ( ctx , p . Model , [ ] mapping . Model { model } , relationField , fields ... ) if err != nil { return nil , err } if len ( relations ) == 0 { return [ ] * Comment { } , nil } result := make ( [ ] * Comment , len ( relations ) ) for i , relation := range relations { result [ i ] = relation . ( * Comment ) } return result , nil }
GetComments gets the 'Comments' relationship for provided input 'model'.
GetComments gets the ' Comments ' relationship for provided input ' model ' .
// Check if primary key has zero value.