-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
Hello, it seems that querying/selecting fields present only in inherited classes misses:
class Transaction
include Mongoid::Document
has_many :events
end
class Event
include Mongoid::Document
belongs_to :transaction
end
class LoanEvent < Event
field :pause, :type => String
end
Now:
muichkine@ubuntu:~/src/white$ rails c test
Loading test environment (Rails 4.0.2)
2.0.0p353 :001 > tr = Transaction.last
There are events
2.0.0p353 :002 > tr.events.count
=> 109
108 are loans:
2.0.0p353 :003 > tr.events.loans.count
=> 108
Some events have the pause field set:
2.0.0p353 :004 > tr.events.loans.map
{ |event| event.read_attribute :pause }=> ["WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", "WITH_INTERESTS_PAYMENT", nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
There are exactly 36:
2.0.0p353 :005 > tr.events.loans.map
{ |event| event.read_attribute :pause }.compact.count
=> 36
and yet:
2.0.0p353 :006 > tr.events.loans.exists(:pause =>true).count
=> 108
Here is the query:
2.0.0p353 :007 > tr.events.loans.exists(:pause =>true)
=> #<Mongoid::Criteria
selector: {"transaction_id"=>BSON::ObjectId('52c1581c7562754a6d040000'), "_type"=>
, "pause"=>{"$exists"=>true}}
options: {:sort=>{"s"=>1}}
class: Event
embedded: false>