Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-2051

chaining only and without together doesn't work

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Looks like only() overwrites without() fields and vice versa.

      I found this when I tried to do an indexOnly query, but couldn't get it to work due to the _type being added:

      Friendship.only(:name).where(name: 'Hello').first
      
      MONGODB (2ms) test_development['friendships'].find({:name=>"Hello"}, {:_type=>1, :name=>1}).limit(-1).sort([[:_id, :asc]])
      

      so I chained the following without, but now the name is gone from the fields returned:

      {{`}}ruby
      Friendship.only(:name).without(:_type).where(name: 'Hello').first

      MONGODB (24ms) test_development['friendships'].find({:name=>"Hello"}, {:_type=>0}).limit(-1).sort([[:_id, :asc]])
      ``

            Assignee:
            Unassigned Unassigned
            Reporter:
            fbjork Fredrik Björk
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: