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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:45:42+00:00 2026-06-10T10:45:42+00:00

I have a visit model as following class Visit < ActiveRecord::Base belongs_to :engineer has_many

  • 0

I have a visit model as following

class Visit < ActiveRecord::Base
  belongs_to :engineer
  has_many :machines
end

What i’m trying to do is find the number of machines associated with a particular engineer by using following code

count = engineer.visits.map(&:machines).flatten.size

is there any better and faster way to do this? I don’t want to create a direct association between engineer and machines.

  • 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-10T10:45:44+00:00Added an answer on June 10, 2026 at 10:45 am

    You can for your query by using the model keywords like join, includes. while selecting one record form a model.

    For your reference http://archives.ryandaigle.com/articles/2008/7/7/what-s-new-in-edge-rails-easy-join-table-conditions, http://railscasts.com/episodes/202-active-record-queries-in-rails-3

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

Sidebar

Related Questions

I have the following Model and Controller files, and when i visit this url,
I have a simple model class User has_many :logs class Logs related in the
I have two models like so: class Visit(models.Model): id = models.AutoField(primary_key=True) name = models.CharField(max_length=65535,
If I have multiple files marked, how do I find/visit all those marked files
I have the following line: RewriteRule ^page.php?var1=([0-9]+)&var2=(.*)&var3=(.*)$ index.php?module=page&var1=$1 When I visit the directory with
I am getting this error while following the tutorial from railstutorial.org. Model class :
I have added the onError method to AppModel as follows: class AppModel extends Model
Hi, I have the following in my view : <form id=list_ad method=get class=adListFilter action=<%=Url.Action(List,
I have a project model that has_many :tasks . I added a nested resource
I have two models, referral and user model. Referral belongs_to User AND user has_one

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.