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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:34:49+00:00 2026-05-27T10:34:49+00:00

I have three objects (List, ListType and GlobalList) and am trying to get a

  • 0

I have three objects (List, ListType and GlobalList) and am trying to get a count of the items in GlobalList with a specific global_id and a specific list_type_id.

This seems to work:

select count(*) from globals_lists gl, lists l where gl.global_id=946 and gl.list_id=l.id and l.list_type_id=10;

The structure is the following:

class ListType < ActiveRecord::Base
 has_many: lists
end

class List < ActiveRecord::Base
   has_many :global_lists
   belongs_to :list_type
end

class GlobalList < ActiveRecord::Base
  belongs_to :list
end

Not sure how to do AR call – at this but can seem to put a where on the join. The list_type_id will always be 10.

a=GlobalList.where("global_id=?",119).joins(:list)

How would I do this ActiveRecord call? Most of the stuff I found via Google involved named scopes, but it seems like this should be able to be done without scopes.

  • 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-27T10:34:50+00:00Added an answer on May 27, 2026 at 10:34 am

    First approach:

    result = GlobalList
      .select("COUNT(*) AS total")
      .where("globals_lists.global_id=? AND lists.list_type_id=?",119, 10)
      .joins(:list)
    

    Then you will account your result using result.total

    Second approach is tho use count method instead of select("COUNT(*) AS total")

    GlobalList      
      .where("globals_lists.global_id=? AND lists.list_type_id=?",119, 10)
      .joins(:list)
      .count 
    

    You can find more about ActiveRecord Query Interface in Rails Guides, or directly at what you are interested in
    count and joins

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

Sidebar

Related Questions

I have a list of objects. These objects have three variables, ID, Name, &
I have three objects. public class ParentClass { public virtual Guid ParentClassId { get;
I am attempting a many-to-many list in one of my objects. I have three
I have a class Player that contains a list of Accessory objects. There are
In my application, I have three collection objects which store data. The data which
I have three ObservableCollections: CharacterCollection, LocationCollection, and ItemCollection. They are all collections of objects;
We have a three-tier architecture consisting of Classic ASP Frontend, VB COM+ Objects and
I have a function that receives three different people objects and generates a new
I have a DataTemplate that is displaying objects with three fields, e.g.: Name =
Basically I have some class objects, each with three properties. Once one class object

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.