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

Relational associations not working

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

      class Shadow
           has_and_belongs_to_many :interests, :class_name => 'Product'
      end
      
      class Product
             has_and_belongs_to_many :viewers, :class_name => 'Shadow'
      end
      
      # This works
      Shadow.where(:created_at.lte => Time.now).count
      => 502
      
      # This doesn't
      Product.first.viewers.where(:created_at.lte => Time.now).count
       => 0 
      

      Did I set up the association incorrectly? I'm confused. It seems that I can't get any sort of where() queries working with associations.

      mongoid (2.0.2)
      rails (3.1.0.rc1)

            Assignee:
            Unassigned Unassigned
            Reporter:
            FestivalBobcats FestivalBobcats [X]
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: