in controller, after reprioritizing "child", lists children in new order: @child.parent.children.sort_by{|g| g.priority } this, surprisingly, doesn't work: @child.parent.children.order(priority: :asc) why doesn't .order work? instead of sorting correctly, it's sorting previous order before operation run, assume it's using cached results (the query run before in operation). how 1 bust cache, if indeed problem? i've tried @child.reload after reprioritizing no avail. if have ordering on children association might try use reorder apply new ordering: @child.parent.children.reorder(priority: :asc)
i think i'm preventing nested queries as possible, i'm not sure. understand calls here can executed in single select query, did simplify example. // example in typescript // find user user.find({where:{username:'user'}}) // if found user .then(function(user) { return user.find({where:{username:'other_user'}}) // if found other_user .then(function(other_user) { // stuff return whatever_i_need } // if went wrong, go straight parent catch .catch(function(err) { // stuff throw new error() } } // if previous .then() returned success .then(function(data) { return user.find({where:{username:'yet_another_user'}}) // if found yet_another_user .then(function(yet_another_user) { // stuff return whatever_i_need_again ...
Comments
Post a Comment