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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:32:39+00:00 2026-05-17T00:32:39+00:00

(Hi Dr. Nick!) I’m trying to tighten things up for our app admin, and

  • 0

(Hi Dr. Nick!)

I’m trying to tighten things up for our app admin, and in a few places we have some pretty skeezy code.

For example, we have Markets, which contain Deals. In several places, we do something like this:

@markets = Market.find(:all, :select => ['name, id'])
@deals = Deal.find(:all, :select => ['subject, discount_price, start_time, end_time'], :conditions => ['start_time >= ? AND end_time <= ?', date1 date2])

Then in the corresponding view, we do something like this:

@markets.each do |m|
  =m.name
end

@deals.sort!{ |a,b| a.market.name <=> b.market.name }
@deals.each do |d|
  =d.subject
  =d.market.name
end

This runs a stupid amount of queries: one to get the market names and ids, then another to get all the deal info, and then for each deal (of which there are thousands), we run yet another query to retrieve the market name, which we already have!

Tell me there is a way to get everything I need with just one query, since it’s all related anyway, or at least to clean this up so it’s not such a nightmare.

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-17T00:32:40+00:00Added an answer on May 17, 2026 at 12:32 am

    You can write like this way ..

    @deals_with_market_name = Deal.find(:all, :include => :market, 
    :select => ['subject, discount_price, start_time, end_time,market.name as market_name'], 
    :conditions => ['start_time >= ? AND end_time <= ?', date1 date2], 
    :order => "market.name")
    

    And in view …

    @deals.each do |a|
      =a.subject
      =a.market_name
    end
    

    Try it…

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

Sidebar

Related Questions

I have the following code which it was provided by Nick in a previous
Nick Craver really helped me out alot with this code in this thread jQuery
So I followed Nick Johnson's instructions on how to forward a naked domain: http://blog.notdot.net/2009/12/Naked-domains-on-App-Engine
I have three records in a table example: *Usernames* *email* *city* Nick nick@example.com London
I have been struggling with this jQuery Validation Plugin. Here is the code: <script
With the help of Nick Craver, I am now able to have two forms
Using Rebol/View 2.7.7, I'm trying to create a card game based on Nick's Rebol
I have json in this format: { minci88: { idUser: 2775040, nick: minci88, photo:
(hello dr.Nick) :) So I posted a question yesterday about a content loader plugin
I got a query: SELECT a.nick,grp,count(*) FROM help_mails h JOIN accounts a ON h.helper=a.id

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.