> irb(main):036:0> rights.size > => 175 > irb(main):037:0> rights.each do |ri| > irb(main):038:1* p ri.role.name > irb(main):039:1> end > "Permissions Admin" > ..snip...
> Which of course cannot be the first Role name in the sorted list
> obviously something basic is escaping me
Sorting by a "foreign key" field is not possible in mongodb because mongodb does not have joins.
you can change your schema design to use embedded relationships http://mongoid.org/docs/relations/embedded.html embedding rigths in role, but that will change the behavior of Roles not allowing make queryins use Role model.
> irb(main):036:0> rights.size > => 175 > irb(main):037:0> rights.each do |ri| > irb(main):038:1* p ri.role.name > irb(main):039:1> end > "Permissions Admin" > ..snip...
> Which of course cannot be the first Role name in the sorted list
> obviously something basic is escaping me
> Sorting by a "foreign key" field is not possible in mongodb because mongodb does not have joins.
> you can change your schema design to use embedded relationships http://mongoid.org/docs/relations/embedded.html > embedding rigths in role, but that will change the behavior of Roles not allowing make queryins use Role model.
---- I sort of need Right class on its own and not embedded for other purposes but I thought that was the point of MongoID associations and identity_map but apparently not.
For now, I am sorting manually (Right.all.sort{|a,b| a.role.name <=> b.role.name}) and then had to make an adjustment (a new will_paginate_array_helper module) to allow will_paginate to paginate the array but it is working.
> > irb(main):036:0> rights.size > > => 175 > > irb(main):037:0> rights.each do |ri| > > irb(main):038:1* p ri.role.name > > irb(main):039:1> end > > "Permissions Admin" > > ..snip...
> > Which of course cannot be the first Role name in the sorted list
> > obviously something basic is escaping me
> > Sorting by a "foreign key" field is not possible in mongodb because > mongodb does not have joins.
> > you can change your schema design to use embedded relationships > http://mongoid.org/docs/relations/embedded.html > > embedding rigths in role, but that will change the behavior of Roles not > allowing make queryins use Role model. > ---- > I sort of need Right class on its own and not embedded for other purposes > but I thought that was the point of MongoID associations and identity_map > but apparently not.
> For now, I am sorting manually (Right.all.sort{|a,b| a.role.name <=> > b.role.name}) and then had to make an adjustment (a new > will_paginate_array_helper module) to allow will_paginate to paginate the > array but it is working.
> Thanks
> Craig
Another solution(and better) is copy the role name into the role and using callbacks and atomic update to keep it updated.
>> > irb(main):036:0> rights.size >> > => 175 >> > irb(main):037:0> rights.each do |ri| >> > irb(main):038:1* p ri.role.name >> > irb(main):039:1> end >> > "Permissions Admin" >> > ..snip...
>> > Which of course cannot be the first Role name in the sorted list
>> > obviously something basic is escaping me
>> > Sorting by a "foreign key" field is not possible in mongodb because >> > mongodb does not have joins.
>> > you can change your schema design to use embedded relationships >> > http://mongoid.org/docs/relations/embedded.html >> > embedding rigths in role, but that will change the behavior of Roles not >> > allowing make queryins use Role model. >> ---- >> I sort of need Right class on its own and not embedded for other purposes >> but I thought that was the point of MongoID associations and identity_map >> but apparently not.
>> For now, I am sorting manually (Right.all.sort{|a,b| a.role.name <=> >> b.role.name}) and then had to make an adjustment (a new >> will_paginate_array_helper module) to allow will_paginate to paginate the >> array but it is working.
>> Thanks
>> Craig
> Another solution(and better) is copy the role name into the role and using > callbacks and atomic update to keep it updated.