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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:15:08+00:00 2026-06-14T17:15:08+00:00

Hi I have three tables like the following: class Workitem < ActiveRecord::Base has_many :effort

  • 0

Hi I have three tables like the following:

    class Workitem < ActiveRecord::Base
      has_many :effort
      attr_protected
    end

    class Effort < ActiveRecord::Base
      attr_protected
      belongs_to :workitem
      belongs_to :person
    end

    class Person < ActiveRecord::Base
      attr_accessible :given_name, :mgrid, :surname, :id
      has_many :effort
    end

The idea is to keep track of how many days a person has spent on a particular work item through efforts table. Could somebody verify if my relationships are correct? But this doesn’t seem to work. Am I missing something here?
Also, I can’t understand the has_many :through kind of associations. Can somebody please give me an idea if that is what I’m supposed to use in this case?

  • 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-14T17:15:09+00:00Added an answer on June 14, 2026 at 5:15 pm

    You would usually have the child as a plural object:

    class Workitem < ActiveRecord::Base
      has_many :efforts
      attr_protected
    end
    
    class Person < ActiveRecord::Base
      attr_accessible :given_name, :mgrid, :surname, :id
      has_many :efforts
    end
    

    And I’d recommend using attr_accessible instead of attr_protected

    If a Foo had many Bars and the Bars belonged to many Foos, it might look like this:

    class Foo < ActiveRecord::Base
      has_many :foo_bar
      has_many :bars, through => :foo_bar
    end
    
    class Bar < ActiveRecord::Base
      has_many :foo_bar
      has_many :foos, through => :foo_bar
    end
    
    class FooBar
      belongs_to :foo
      belongs_to :bar
    end
    

    Something like that anyway. There’s a load of help on Railcasts here

    Also, there’s a trillion examples on SO.

    Hope that helps

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

Sidebar

Related Questions

I have three models connected via an has_many_through association. class Board < ActiveRecord::Base has_many
I have three tables like this: Person table: person_id | name | dob --------------------------------
I have three models, basically: class Vendor has_many :items end class Item has_many :sale_items
If I have three different tables like this table_1 Field 1: victories Field 2:
I have three tables: videos, videos_categories, and categories. The tables look like this: videos:
I have three tables. The designs were like student table create table student (studID
I have three tables CLASSES , CHILD_CLASSES , and STUDENTS . CLASSES looks like
I have three tables: Project: ... relations: User: local: authorId foreign: id Users: class:
I have an abstract entity base class defined like this: public abstract class SessionItem
I have a JPA database setup like the following: @Entity public class Contact {

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.