몽고이 (Mongoid)가 어떻게 정렬하는지 이해하려고 할 때 몇 가지 문제가 있습니다. 나는 2 가지 모델 인 Gig와 Venue를 가지고 있으며, 둘 다 belongs_to has_many 관계에 의해 연관되어있다.연결된 모델의 속성을 통해 몽고드 객체 정렬
Ven 객체의 'name'속성으로 Gig에서 객체를 정렬하지 않으려 고합니다.
나는 누군가가 나와 올바른 방향으로 나를 가리킬 수 있기를 바라고 있습니다.
다음은 잘린 모델 설명입니다.
내 쿼리는 다음과 같습니다 : 당신은 몽고에 가입 할 수 없습니다
# Gig Model
class Gig
include Mongoid::Document
include Mongoid::Paperclip
include SearchMagic
belongs_to :owner, :class_name => "User", :inverse_of => :owns
belongs_to :venue
has_and_belongs_to_many :attenders, :class_name => "User", :inverse_of => :attending
has_and_belongs_to_many :artistes
<snip>
end
# Venue Model
class Venue
include Mongoid::Document
include Mongoid::Paperclip
include SearchMagic
has_many :gigs
field :foursquare_id, type: String
embeds_one :address
embeds_many :user_ratings
field :facebook, type: String
field :twitter, type: String
field :website, type: String
field :name, type: String
field :postal, type: String
field :tel, type: String
field :venue_type, type: String
field :description, type: String
field :rating, type: Float, default: 0.0
<snip>
end
# Console
>> Gig.desc('venue.name').map{|f| f.venue.name}
=> ["*SCAPE", "Velvet Underground", "Blujaz Lounge", "Velvet Underground", "Home Club", "Wh
ite House, Emily Hill", "Zouk", "Zouk", "The Pigeonhole", "Home Club", "Home Club", "Home C
lub"]
# sorting doesn't work