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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:47:55+00:00 2026-05-27T18:47:55+00:00

My first problem is that im not quiet sure if this could work at

  • 0

My first problem is that im not quiet sure if this could work at all. But since i’ve already got a lot of help here i’ll at least try to ask something myself.

What i have here is a model ‘thesis’, which has_many ‘tasks’ through a relation model and also has_many ‘checked_tasks’. Now i want to have only those theses where the number of tasks euqals the number of checked_tasks.

class Thesis < ActiveRecord::Base
  has_many :tasks, :through => :relations
  has_many :checkedtasks
end

class Task < ActiveRecord::Base
  belongs_to :relation
end

class CheckedTask < ActiveRecord::Base
  belongs_to :thesis
end

My first idea was simply to to a Thesis.where(self.tasks.count == self.checked_tasks.count) – but i coudn’t figure out what to use instead of the self to get it working.

After that, i tried to do it whit scopes, but that still leaves me with the same problem.

After all, i’m not sure if there is a ‘rails way’ to do that – if so, i’d be very thankful for some help

  • 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-27T18:47:56+00:00Added an answer on May 27, 2026 at 6:47 pm

    You could do

    Thesis.joins(:checked_tasks, :tasks).group("thesis.id").select("thesis.*, count(distinct tasks.id) as task_count, count(distinct checked_tasks.id) as checked_count").having("checked_count = task_count")
    

    But this is quite a pig of a query to run. it really feels like you should be redesigning your data model along the lines suggested by some of the commenters, using the join model between thesis and task to store the checkness of a task for a thesis.

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

Sidebar

Related Questions

I got the problem that the if-statement doesn't work. After the first code line
Not sure where to start on this one -- not sure if the problem
I'm not entirely sure how to post this question, but here goes... I have
Sorry for the vague title, but not quite sure how to summarize this one.
First the practical application that led me to the problem: Given a set of
Problem 2b goes as follows: 2b. For each subject show the first year that
UPDATE: First problem solved, second one described at the bottom of this post. UPDATE2:
It might sound unnecessary, but let me explain my problem first. Probably then it
I'm quite ashemed to ask this question here because I'm sure that I'm missing
I'm sure that this is very straight-forward, however, after scouring the net I can't

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.