@@ -244,9 +244,7 @@ func (crud *CRUD) Attach(model Model, ops ...Option) (err error) {
return
}
scenarios := model.Scenario()
- atomic.AddInt32(&crud.index, 1)
- entity := newEntity(model, opts)
- entity.index = crud.index
+ entity := newEntity(atomic.AddInt32(&crud.index, 1), model, opts)
entity.callback = crud.callback
if len(scenarios) == 0 {
entity.scenarios = []string{ScenarioList, ScenarioCreate, ScenarioUpdate, ScenarioDelete, ScenarioExport, ScenarioView}
@@ -72,7 +72,7 @@ func (e Entities) Less(i, j int) bool {
func (e Entities) Swap(i, j int) {
- e[i], e[j] = e[j], e[j]
+ e[i], e[j] = e[j], e[i]
func (e *Entity) ID() string {
@@ -788,8 +788,9 @@ func (e *Entity) actionMapping(ctx *http.Context) (err error) {
return ctx.Success(e.getMappingValue(namespace))
-func newEntity(model Model, opts *Options) *Entity {
+func newEntity(index int32, model Model, opts *Options) *Entity {
entity := &Entity{
+ index: index,
model: model,
opts: opts,
createdAt: time.Now(),