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

  • Home
  • SEARCH
  • 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 6878549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:44:15+00:00 2026-05-27T04:44:15+00:00

Suppose we have two models, Task and User. So a user can have many

  • 0

Suppose we have two models, Task and User.
So a user can have many tasks and tasks should be able to have many users too. But, a task should also have a unique creator who is also a user.

Exemple:

A task in this context is like this:
Task ID, Task Creator, Users who should do the task

User_1 creates a task and he is then the creator.
User_1 specifies User_2 and User_3 as users who should do the task. So these two last users are not creators of task.

How do I create this models so that if I have a task object, I can find it’s creator and users who should complete it. And how do I do, if I have a user, to find all tasks he created and all tasks he should complete.

  • 1 1 Answer
  • 3 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-05-27T04:44:16+00:00Added an answer on May 27, 2026 at 4:44 am

    You’ll need a many-to-many relationship between the Tasks and Users, and you need an additional one-to-many relationship between Users and Tasks, pointing to the creator (User).

    Something along these lines: (I usually use Mongoid, so double-check the syntax for the relations in the MongoMapper API – link below.. you might to manually specify :foreign_key and :class)

    The idea is that you have two relationships between the models, one which models the many-to-many relationship
    with which you get either to the assigned_users or assigned_tasks, and a one-to-many relationship with which you get to either the creator of a task, or the created_tasks for a given user. If you chose these names for the relationships, it will be clear which is which.

    class Task
      include MongoMapper::Document
      key :title, String , :required => true
    
      key :user_ids , Array
      has_many :users, :in => user_ids     # , :as => :assigned_users
    
      key :creator_id , ObjectId
      belongs_to: user, :as => :creator
    
    end
    
    class User
      include MongoMapper::Document
      key: name, String, :required => true
    
      has_many :tasks           # , :as => :assigned_tasks
    
      has_many :tasks, :as => :created_tasks
    end
    

    See:

    http://mongomapper.com/documentation/plugins/associations.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So suppose I have two Models -- Project and Task I want user to
Suppose you have two models, User and City, joined by a third model CityPermission:
Suppose I have two models, A and B , where an A can have
Suppose I have two fingers touching iPhone's screen but just one is moving. TouchesMoved
I have two models I want to connect with an m-to-m relationship, but I
Suppose I have a simple to-do list application. The application contains two models: lists
I'm investigating on how validates_presence_of actually works. Suppose I have two models class Project
Suppose I have two models A and B Now I want to copy some
I have two models. class User has_one :spec, :dependent => :destroy # returns true
Let's assume we have two models: User and Token . A user may have

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.