FindCollectionReferences returns information for all relation fields referencing the provided collection. If the provided collection has reference to itself then it will be also included in the result. To exclude it, pass the collection id as the excludeIds argument.
(collection *Collection, excludeIds ...string)
| 119 | // also included in the result. To exclude it, pass the collection id |
| 120 | // as the excludeIds argument. |
| 121 | func (app *BaseApp) FindCollectionReferences(collection *Collection, excludeIds ...string) (map[*Collection][]Field, error) { |
| 122 | collections := []*Collection{} |
| 123 | |
| 124 | query := app.CollectionQuery() |
| 125 | |
| 126 | if uniqueExcludeIds := list.NonzeroUniques(excludeIds); len(uniqueExcludeIds) > 0 { |
| 127 | query.AndWhere(dbx.NotIn("id", list.ToInterfaceSlice(uniqueExcludeIds)...)) |
| 128 | } |
| 129 | |
| 130 | if err := query.All(&collections); err != nil { |
| 131 | return nil, err |
| 132 | } |
| 133 | |
| 134 | result := map[*Collection][]Field{} |
| 135 | |
| 136 | for _, c := range collections { |
| 137 | for _, rawField := range c.Fields { |
| 138 | f, ok := rawField.(*RelationField) |
| 139 | if ok && f.CollectionId == collection.Id { |
| 140 | result[c] = append(result[c], f) |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | return result, nil |
| 146 | } |
| 147 | |
| 148 | // FindCachedCollectionReferences is similar to [BaseApp.FindCollectionReferences] |
| 149 | // but retrieves the Collection from the app cache instead of making a db call. |
no test coverage detected