Documentation ¶
Index ¶
- type HasManyRelation
- func (r *HasManyRelation) Get(results interface{}, sort string, skip, limit int64) error
- func (r *HasManyRelation) GetWithOptions(results interface{}, options ...*options.FindOptions) error
- func (r *HasManyRelation) SimpleGet(results interface{}, limit int64) error
- func (r *HasManyRelation) Sync(docs interface{}) error
- func (r *HasManyRelation) SyncWithoutRemove(docs interface{}) error
- type HasOneRelation
- type IDField
- type SyncedHook
- type SyncingHook
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HasManyRelation ¶
type HasManyRelation struct {
// contains filtered or unexported fields
}
func HasMany ¶
func HasMany(model mgm.Model, related mgm.Model) *HasManyRelation
HasMany returns new instance of the "has many" relation ship.
func HasManyWithOptions ¶
func HasManyWithOptions(model mgm.Model, related mgm.Model, foreignKey string) *HasManyRelation
HasManyWithOptions gets HasManyRelation options and returns new instance of it.
func (*HasManyRelation) Get ¶
func (r *HasManyRelation) Get(results interface{}, sort string, skip, limit int64) error
Get method get the list of related models with provided filter,limit,... if not found, returns the Mongo Go driver not found error.
func (*HasManyRelation) GetWithOptions ¶
func (r *HasManyRelation) GetWithOptions(results interface{}, options ...*options.FindOptions) error
Get method get the list of related models with provided filter,limit,... if not found, returns the Mongo Go driver not found error.
func (*HasManyRelation) SimpleGet ¶
func (r *HasManyRelation) SimpleGet(results interface{}, limit int64) error
SimpleGet method get the list of related models if not found, returns the Mongo Go driver not found error. sort is the sort field. you can sort descending by adding a `-` to the sort field. e.g `-created_at`
func (*HasManyRelation) Sync ¶
func (r *HasManyRelation) Sync(docs interface{}) error
Sync method sync the relations: If provided models is nil(or length is zero): it remove the related models in the DB. If provided models is not nil and length is not zero: udpate new items, and remove items that are not in the provided list. Use sync just when your 1-m model contains just few m mdoel. otherwise use SyncWithoutRemove
func (*HasManyRelation) SyncWithoutRemove ¶
func (r *HasManyRelation) SyncWithoutRemove(docs interface{}) error
SyncWithoutRemove method sync the relations without removing items that are not in the provided list.
type HasOneRelation ¶
type HasOneRelation struct {
// contains filtered or unexported fields
}
func HasOne ¶
func HasOne(model mgm.Model, related mgm.Model) *HasOneRelation
HasOne returns new instance of the "has one" relation ship.
func HasOneByOptions ¶
func HasOneByOptions(model mgm.Model, related mgm.Model, foreignKey string) *HasOneRelation
HasOneByOptions gets HasOneRelation options and returns new instance of it.
func (*HasOneRelation) Get ¶
func (r *HasOneRelation) Get(m mgm.Model) error
SimpleGet method get the single related model. if not found, returns the Mongo Go driver not found error.
func (*HasOneRelation) Sync ¶
func (r *HasOneRelation) Sync(model mgm.Model) error
Sync method sync the relations: If provided model is nil: it remove the related model in the DB. If provided model is not nil: sync it. insert new model, otherwise upsert provided model.
type IDField ¶
IDField struct contain model's ID field. it also implements the SyncingHook to set id before sync the model. you can use this IDField instead of the mgm IDField.
func (*IDField) PrepareID ¶
PrepareID method prepare id value to using it as id in filtering,... e.g convert hex-string id value to bson.ObjectId
type SyncedHook ¶
type SyncedHook interface {
Synced() error
}
SyncedHook is the interface to implement hook to call after sync your model.
type SyncingHook ¶
type SyncingHook interface {
Syncing() error
}
SyncingHook is the interface to implement hook to call before sync your model.