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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:14:40+00:00 2026-06-18T06:14:40+00:00

I have a Lesson model that contains about 50 fields that all reference a

  • 0

I have a Lesson model that contains about 50 fields that all reference a Grade model. The grades model has a simple list 0-8 that is used as a lessons graded value.

Is there a way to avoid filling up my model with 50 lines of:

 belongs_to :walking, :class => 'Grade'
 belongs_to :running, :class => 'Grade'   
 belongs_to :crawling, :class => 'Grade' 
 ...

postgres database

  • 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-18T06:14:42+00:00Added an answer on June 18, 2026 at 6:14 am

    You could do this:

    fields = %w[walking running crawling] # list all 50 of them here
    fields.each { |field| belongs_to field.to_sym, :class => 'Grade' }
    

    That will at least save you from having to write all the lines out, but you still need to list the names of the associations (walking, running, crawling, etc.) for it to work (as I’ve indicated above).

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

Sidebar

Related Questions

I have model that looks like this: public class Lesson { public int Id
I created a model for a thing called a Lesson that has :content and
In Django (1.0.2), I have 2 models: Lesson and StatLesson. class Lesson(models.Model): contents =
I have a table that includes some student group name, lesson time, day names
I have dates in my script related to some teaching lessons. Each lesson has
I have structure like this class Lesson { List<Sign> signs { get; set; }
I have a data model in Doctrine/symfony. I have a 'Course' which has many
I have a CGridView widget for Lesson model $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'lesson-grid', 'dataProvider'=>$model->search(), 'filter'=>$model, ...
I'm new in DDD. I have a Topic entity and Lesson entity. Topic has
I have a versioning mechanism for a Lesson model: class Lesson < ActiveRecord::Base attr_accessible

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.