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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:16:14+00:00 2026-05-30T02:16:14+00:00

I have the following objects: Products, Ratings, and Users. I am trying to filter

  • 0

I have the following objects: Products, Ratings, and Users. I am trying to filter and select a number of Products that the User owns (through a has_many :through relationship with UserProducts) and average a certain column the Ratings table that matches their User ID and the correct Product ID.

So, my function is something along these lines:

def find_rating(criteria)
  product = self.products.find(:all, :conditions => ["criteria = ?", criteria])
  rating = self.ratings.where("product_id = ?", product).average(:overall)
end

I think that I’m going about this the wrong way, because I’m trying to find a product_id by passing an entire array of data consisting of multiple products. But, I think of using a more traditional loop and that seems convoluted. Can someone point me in the right direction for solving this problem? Thanks!

  • 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-30T02:16:16+00:00Added an answer on May 30, 2026 at 2:16 am

    If product is a single entry, as it appears to be in your code, I would do this:

    rating = self.products.find_by_criteria(criteria).ratings.average(:overall)
    

    If it’s an array of products, this method may help you: http://apidock.com/rails/ActiveRecord/Batches/ClassMethods/find_each

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

Sidebar

Related Questions

I have the following views: def tag_page(request, tag): products = Product.objects.filter(tag=tag) return render(request, 'shop/tag_page.html',
I have the following 2 objects: User and DomainUser User.java: package com.domain; import java.io.Serializable;
I have the following sort descriptors that sort an array of my business objects,
I have the following setup of models: User - has_many File (for userpics) Gallery
In C# if I have the following object: IEnumerable<Product> products; and if I want
I have following nested objects. I am using @Valid for validation in my controller.
I have the following objects: @JsonFilter(myFilter) public class Person { private Name name; private
I have the following objects. An IEnumerable <Agency > Agencies, which then contains BusinessUnits
I currently have the following objects persisting successfully: Person first name, etc. Exams title,
I have the following domain objects: public class UserSpecialization : PersonSpecialization, IUserSpecialization { public

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.