Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
identity map, includes and sorting
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Craig White  
View profile  
 More options Apr 9 2012, 7:33 pm
From: Craig White <craig.wh...@ttiltd.com>
Date: Mon, 9 Apr 2012 16:33:53 -0700
Local: Mon, Apr 9 2012 7:33 pm
Subject: identity map, includes and sorting
I can't seem to make it work.

Simplified...

class Right
  include Mongoid::Document
  field :controller, :type => String
  field :action,     :type => String

  belongs_to :role
end

class Role
  include Mongoid::Document
  include Mongoid::Timestamps

  field :name ,      :type => String
  has_many           :rights
  index :name,       :unique => true
end

config/mongoid.yml
development:
  host: localhost
  database: tti_framework_development
  identity_map_enabled: true

and then in the console, I'm trying to get a list of 'Rights' sorted by the associated 'Role' name

irb(main):035:0> rights = Right.all(:sort => 'role.name').includes(:roles)
=> #<Mongoid::Criteria
  selector: {},
  options:  {:sort=>"role.name"},
  class:    Right,
  embedded: false>

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

--
Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.wh...@ttiltd.com
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com

Need help communicating between generations at work to achieve your desired success? Let us help!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Durran Jordan  
View profile  
 More options Apr 10 2012, 2:32 am
From: Durran Jordan <dur...@gmail.com>
Date: Tue, 10 Apr 2012 08:32:45 +0200
Local: Tues, Apr 10 2012 2:32 am
Subject: Re: [mongoid] identity map, includes and sorting

The sort option is incorrect - I'm actually surprises the ruby driver
didn't raise an error for that. You want:

Right.asc("role.name").includes(:roles)

2012/4/10 Craig White <craig.wh...@ttiltd.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig White  
View profile  
 More options Apr 10 2012, 11:33 am
From: Craig White <craig.wh...@ttiltd.com>
Date: Tue, 10 Apr 2012 08:33:09 -0700
Local: Tues, Apr 10 2012 11:33 am
Subject: Re: [mongoid] identity map, includes and sorting
Seems that the ruby driver is fairly tolerant of much of my abuse but alas...

rights = Right.asc("role.name").includes(:roles)

still gives me an 'unsorted' list.

irb(main):045:0> rights = Right.asc("role.name").includes(:roles)
=> #<Mongoid::Criteria
  selector: {},
  options:  {:sort=>[["role.name", :asc]]},
  class:    Right,
  embedded: false>

irb(main):046:0> rights.each do |ri|
irb(main):047:1* p ri.role.name
irb(main):048:1> end
"Permissions Admin"
"Permissions Create"
... snip...

Craig

On Apr 9, 2012, at 11:32 PM, Durran Jordan wrote:

--
Craig White ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ craig.wh...@ttiltd.com
1.800.869.6908 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ www.ttiassessments.com

Need help communicating between generations at work to achieve your desired success? Let us help!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kuadrosx (Jorge Cuadrado)  
View profile  
 More options Apr 10 2012, 12:31 pm
From: "kuadrosx (Jorge Cuadrado)" <kuadro...@gmail.com>
Date: Tue, 10 Apr 2012 11:31:05 -0500
Local: Tues, Apr 10 2012 12:31 pm
Subject: Re: [mongoid] identity map, includes and sorting

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.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Craig White  
View profile  
 More options Apr 10 2012, 2:07 pm
From: Craig White <craig.wh...@ttiltd.com>
Date: Tue, 10 Apr 2012 11:07:30 -0700
Local: Tues, Apr 10 2012 2:07 pm
Subject: Re: [mongoid] identity map, includes and sorting

On Apr 10, 2012, at 9:31 AM, kuadrosx (Jorge Cuadrado) wrote:

----
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
kuadrosx (Jorge Cuadrado)  
View profile  
 More options Apr 10 2012, 2:56 pm
From: "kuadrosx (Jorge Cuadrado)" <kuadro...@gmail.com>
Date: Tue, 10 Apr 2012 13:56:24 -0500
Local: Tues, Apr 10 2012 2:56 pm
Subject: Re: [mongoid] identity map, includes and sorting

Another solution(and better) is copy the role name into the role and using
callbacks and atomic update to keep it updated.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Alexey Savartsov  
View profile  
 More options Apr 10 2012, 3:07 pm
From: Alexey Savartsov <asavart...@gmail.com>
Date: Tue, 10 Apr 2012 23:07:58 +0400
Local: Tues, Apr 10 2012 3:07 pm
Subject: Re: [mongoid] identity map, includes and sorting
There is also mongoid_denormalize gem which I'm widely using for that.

On Tue, Apr 10, 2012 at 10:56 PM, kuadrosx (Jorge Cuadrado)

-- Alexey

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »