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 7887353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:33:29+00:00 2026-06-03T05:33:29+00:00

I have a many-to-many relationship between User and Task model. A task can have

  • 0

I have a many-to-many relationship between User and Task model.

A task can have many users, but it should keep track of its original creator (if a user creates one by @user.tasks.create). I was wondering how could I do this.

I would have to create a new column field called “creator” in the tasks table. I could then initalise a task in the following way:

@user.tasks.create(:creator=>@user)

Is there a way of not having to add the arguments since the creator will always be the user that instantiated the task.

Thanks!

EDIT

My User model has:

 has_many :taskization
 has_many :tasks, :through => :taskization

My Tasks model has:

  has_many :taskization
  has_many :users, :through => :taskization
  • 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-03T05:33:30+00:00Added an answer on June 3, 2026 at 5:33 am

    it sounds like you’re indicating that the ‘original_creator’ is an attribute of the Task. For each Task record, you want to keep track of which User originally created it.

    So, modeling that seems like you would require both:

    # return the User object of the original task creator
    @original_creator_user = @task.original_creator  
    

    as well as

    # get all users of this task
    @users = @task.users
    

    to work.

    This requires two different relationships between Task objects and User objects.

    class User < ActiveRecord::Base
      # tasks for this user
      has_many :taskization
      has_many :tasks, :through => :taskization
    
      # tasks this user was the original creator of
      has_many :created_tasks, :class_name => "Task" 
    
    end
    
    class Task < ActiveRecord::Base
      # users of this task
      has_many :taskization
      has_many :users, :through => :taskization
    
      # user who originally created this class
      belongs_to :original_creator, :class_name => "User"
    
    end
    

    Notice that the ‘creator’ relationship is not a :through task, it’s a relationship directly between the two objects.

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

Sidebar

Related Questions

Let's say I have a many-to-many relationship between users and group. A user can
I have a many-to-many relationship between User s and Task s. I want the
Let's say you have a one-to-many relationship between Users and Orders (where one user
I have a many-to-many relationship between two models, Lists and Users. When a user
I have a many-to-many relationship between users and groups and I have a table
I have a one to many relationship between Admins and Users. Admin has_many :users
I have a Users table and a Networks table with a many-to-many relationship between
I have a standard many-to-many relationship between users and roles in my Rails app:
I have two domain classes with a many-2-many relationship between them, e.g. User and
I have a self-referencing many-to-many relationship between users and managers that looks like this:

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.