Esempio n. 1
0
func (c *C) Update(a iface.Filter, data map[string]interface{}) error {
	upd := map[string]interface{}{
		"$set": data,
	}
	has_files := len(c.fileBiz) > 0
	if has_files {
		ids, err := a.Ids()
		if err != nil {
			return err
		}
		err = c.moveFiles(a.Subject(), ids[0].String())
		if err != nil {
			return err
		}
		upd["$addToSet"] = eachIfNeeded(fileNames(c.fileBiz))
	}
	err := a.Update(upd)
	if err != nil {
		return err
	}
	if c.Hooks != nil {
		c.Hooks.Select("Updated").Fire(a)
		c.Hooks.Select(a.Subject() + "Updated").Fire(a)
	}
	return nil
}
Esempio n. 2
0
func (f *Filter) Reduce(a ...iface.Filter) (iface.Filter, error) {
	l := len(a)
	if l == 0 {
		return &Filter{}, fmt.Errorf("Nothing to reduce.")
	}
	var prev iface.Filter
	prev = f
	for _, v := range a {
		ids, err := prev.Ids()
		if err != nil {
			return &Filter{}, err
		}
		v.AddParents("_"+prev.Subject(), ids)
		prev = v
	}
	return prev, nil
}