Skip to content
This repository has been archived by the owner on Jan 15, 2024. It is now read-only.

Aliased field names with moped #82

Closed
wielgosm opened this issue Sep 30, 2012 · 2 comments
Closed

Aliased field names with moped #82

wielgosm opened this issue Sep 30, 2012 · 2 comments
Milestone

Comments

@wielgosm
Copy link

I have a Car document which has a field with a symbol of :b, aliased as :year.

class Car 
  include Mongoid::Document

  field :a, :as => :name, :type => String
  field :b, :as => :year, :type => Integer

  belongs_to              :manufacturer
  has_and_belongs_to_many :customers

  validates :name,         :presence => true
  validates :year,         :presence => true
  validates :manufacturer, :presence => true, :uniqueness => { :scope => [:name,:year,:manufacturer] }
end

Using aliased field name with distinct does not work:

# Does not work - returns an empty array
manufacturer.cars.distinct(:year)

Using non-aliased field name works:

# It's all good!
manufacturer.cars.distinct(:b)

I was't sure if this issue should have been placed here or in the mongoid/mongoid project.

Thanks!

@durran
Copy link
Member

durran commented Oct 1, 2012

This should be in Mongoid, since Moped should know nothing about Mongoid... I'll move it over there.

durran added a commit to mongodb/mongoid that referenced this issue Oct 4, 2012
durran added a commit to mongodb/mongoid that referenced this issue Oct 4, 2012
@durran
Copy link
Member

durran commented Oct 4, 2012

I've fixed in Mongoid, as per the referenced commits.

@durran durran closed this as completed Oct 4, 2012
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants