2

I have a model that belongs_to another:

class Permission
  include Mongoid::Document
  belongs_to :action
  field :action_id, type: String

And a corresponding has_many model:

class Action
  include Mongoid::Document
  has_many :permissions

I am seeing that 2 basic ActiveRecord queries are not working:

First, sending the object instead of the object id does not work:

action = Action.first
permissions = Permission.where(action: action)
permissions.count # this is always 0

However, if I use the id, it works fine:

Permission.where(action_id: action.id) # this works fine

Second, sending an array of ids does not work, ever:

Permission.where(action_id: [action.id]) # always empty

Does mongoid not support basic ActiveRecord queries? If not, for the first problem, I can work around it by always using the object id, but for the second, how do I search by an array of targets?

Thanks for any help, Kevin

rails_id
  • 8,120
  • 4
  • 46
  • 84
user1130176
  • 1,772
  • 1
  • 23
  • 33

1 Answers1

0

Look into Ruby on Rails reserved words. There is a possibility that is what is causing the .where to break.

http://www.rubymagic.org/posts/ruby-and-rails-reserved-words