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

has_one relations (by ref) don't return proxy objects-->cannot call scopes

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.0
    • Affects Version/s: None
    • Component/s: None
    • None

      I've got this example of a has_one relation (by reference):

      class Profile
        include Mongoid::Document
      
        has_one :graph
      end
      
      class Graph
        include Mongoid::Document
        field :labels, type: Array  
      
        belongs_to :profile
      
        scope :lightweight, without(:graph_file)
      end
      
      profile.graph.lightweight.labels  # => undefined method `lightweight' for #<Graph: ....>
      

      I've tried this both with the latest head version as well as with gem version 2.4.11. According to the docs: All relation objects in Mongoid are proxies to the actual document or documents themselves... This doesn't seem to be the case here. The same goes for association extensions defined with a block on the has_one itself.

      I do get the expected behavior (ability to invoke the scope through the proxy) when using a has_many association.

            Assignee:
            Unassigned Unassigned
            Reporter:
            wolframarnold wolframarnold
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: