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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:19:42+00:00 2026-05-29T17:19:42+00:00

My Model: class Student < ActiveRecord::Base has_many :lack_knowledge_points, :through => :knowledge_point_infos, :conditions => [‘knowledge_point_infos.level

  • 0

My Model:

class Student < ActiveRecord::Base
has_many :lack_knowledge_points, :through => :knowledge_point_infos,
:conditions => ['knowledge_point_infos.level <= ?',10],:source => :knowledge_point

I want that 10 be dynamic

What is my best practice?

Define a method and find_by_sql? Or can Rails do something else for me?

  • 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-05-29T17:19:49+00:00Added an answer on May 29, 2026 at 5:19 pm

    I am not clear how you want ‘level’ to be dynamic. Anyway, you could use scope with lambda or define a method in the model.

    #If you want it to return an array
    def lack_knowledge_points(threshold)
      knowledge_point_infos.where('level <= ?', threshold).map{|info|info.knowledge_point}
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

e.g. I have a model Student: class Student < ActiveRecord::Base def self.do_something ss=Student.find_by_sex m
I'm trying to validate a model Student like this; class Student < ActiveRecord::Base belongs_to
I have this Task model: class Task < ActiveRecord::Base acts_as_tree :order => 'sort_order' end
I have such terrible models: class ParentalRelation < ActiveRecord::Base belongs_to :parent belongs_to :student belongs_to
I've got my models setup for a many-to-many relationship: class Workshop < ActiveRecord::Base has_many
Here are my models: class BillingProfile < ActiveRecord::Base belongs_to :student attr_accessible :cost end class
My code: class School(models.Model): pass class Student(models.Model): school = models.ForeignKey(School) TYPE_CHOICES = ( ('ug',
I have a similar model Class Student(models.Model): A simple class which holds the basic
Take the following simple object model for example: class Course has_many :enrollments has_many :students,
class Student(db.Model): teacher = db.ReferenceProperty(Teacher, collection_name='students') name = db.StringProperty(required=True) zip_code = db.IntegerProperty(required=True) square_footage =

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.