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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:02:46+00:00 2026-06-04T06:02:46+00:00

If you have the following models: client has_many :projects project has_many :tasks tasks has_many

  • 0

If you have the following models:

client has_many :projects
project has_many :tasks
tasks has_many :timeentries

and

timeentries belongs_to :task
task belongs_to :project
project belongs_to :client

Then do you need model statements like:

timeentries belongs_to project :through => :tasks
client has_many :tasks, :through => :projects

Thanks

  • 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-04T06:02:47+00:00Added an answer on June 4, 2026 at 6:02 am

    The simple answer is that you don’t have to, but you might want to. It depends a bit how you are going to use your model- if you want to be able to access each end of the relationship from the other then you might need it. So if you wanted to be able to access Project directly from TimeEntries.Project then you might want it, if you are happy to go through TimeEntries.Task.Project then you don’t need the explicit relationship, which can complicate matters further on.

    Be aware of Has_and_belongs_to_many :through which is for cases where you have a many-to-many relationship using an intermediary table purely to represent the relationship so the intermediary doesn’t need it’s own model.

    This is quite common in two-way many-to-many relationships- supposing you have a tag cloud of some kind you might have something like this:

      Article               ArticleTag       Tag
        Id                    ArticleId        Id         
        Title                 TagId            Text
        Text
    

    There one article can have many tags, one tag can be applied to many articles, so you don’t want to bind either in the table. So the Article has_many Tags through ArticleTag.

    This gives a handy summary of associations in Rails.

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

Sidebar

Related Questions

I have the following: app/models/order.rb class Order < ActiveRecord::Base belongs_to :client accepts_nested_attributes_for :client end
In my GWT app I have the following model class: import com.google.gwt.user.client.rpc.IsSerializable; public class
I have following models setup in my Django application class School(models.Model): name = models.TextField()
I have the following models: class Person < ActiveRecord::Base has_many :accounts, :through => :account_holders
I have the following models: class FieldEntryValue < ActiveRecord::Base belongs_to :field_entry end and class
I have the following models class Person(models.Model): name = models.CharField(max_length=100) class Employee(Person): job =
I have the following models: class City(models.Model): name = models.CharField(max_length=100) class Pizza(models.Model): name =
i have the following models setup class Player(models.Model): #slug = models.slugField(max_length=200) Player_Name = models.CharField(max_length=100)
I have the following def in the client model: def cli_full_name [f_name, mi, l_name].join('
Say I have the following in my models.py : class Company(models.Model): name = ...

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.