Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7919067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T15:44:00+00:00 2026-06-03T15:44:00+00:00

I have a group model. I want to query a group to see if

  • 0

I have a group model. I want to query a group to see if user exists in it. Typically this is much easier using embedded documents but unfortunately I cannot do that in this case. In an embedded scenario I would do the following. How can I do this query in a referenced scenario.

Note:** I do not want to use habtm relationships.

Query

Matter.where(:'matter_counsels._id' => the_id)

Classes

class Matter
  include Mongoid::Document

  # Relationships
  has_many :matter_counsels # subclass of MatterRelationship
  has_many :matter_clients # subclass of MatterRelationship
  has_many :matter_opposing_parties # subclass of MatterRelationship
  has_many :matter_related_parties # subclass of MatterRelationship

end


class MatterRelationship
  include Mongoid::Document

  belongs_to :matter
end
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T15:44:01+00:00Added an answer on June 3, 2026 at 3:44 pm

    I have to admit the example I had above wasn’t clear. I updated the problem along with my solution.

    class Matter
      include Mongoid::Document
    
      # Relationships
      has_many :matter_counsels # subclass of MatterRelationship
      has_many :matter_clients # subclass of MatterRelationship
      has_many :matter_opposing_parties # subclass of MatterRelationship
      has_many :matter_related_parties # subclass of MatterRelationship
    
      # Finder Scopes
      class << self
    
        # finds a type of matter relationship by user
        def for_user(user,type)
          user_id = user.id.to_s
          matter_ids = MatterRelationship.where(contact_id: user_id, _type: type).collect{ |i| i.matter_id.to_s }
          where(:_id.in => matter_ids)
        end
    
      end
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Rails 3. I have a Product model and a Group model
I am using the standard User model (django.contrib.auth) which comes with Django. I have
I have a 'User' model which is related to a 'Group' model via HABTM
I have the following model in my Django app: class Group(models.model): name=models.CharField(max_length=30) users=Models.ManyToManyField(User) In
I have an object $this->user which is of model User . This object is
I have a user, membership and group model. A user has many memberships, and
I have the following :has_many, :through association for my models: Group Model: has_many :group_users
I have the following model structure: class Group < ActiveRecord::Base has_many :group_products, :dependent =>
I have the following code to generate a table listing brand/model/submodel/style for a group
I have three models: User Image Group . User belongs to an image; Group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.