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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:34:24+00:00 2026-05-23T21:34:24+00:00

I`m having a problem with search query in Rails 3 application using Mongoid. My

  • 0

I`m having a problem with search query in Rails 3 application using Mongoid. My models are:

class Offer
  has_many :waypoints
end

class Waypoint
  belongs_to :offer
  field: address
  field: order, type: Integer
end

So each Offer has several Waypoints and these Waypoints has order. Waypoint with the smallest order is start point, with the biggest – destination point.

Task: We have “To” and “From” addresses. We need to find all the offers, which waypoints contain these addresses in proper order.

Problem: I can`t find useful query for it. In mongoid documentation I found smth like

Offer.where(“waypoints.address” => “Berlin”) but it works only if Waypoints were embedded.

Which solutions for such a problem do you know?

P.S.
So I probably will create another table WaypointsCache with field like (for each offer there will be several caches with different from-to combos):

class WaypointCache
  field: from
  field: to
  field: offer_id
end
  • 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-23T21:34:24+00:00Added an answer on May 23, 2026 at 9:34 pm

    If the goal is to find all Offers with a waypoint address of Berlin, then you have a couple of options.

    1. Move the waypoints to be embedded inside of the offer.
    2. execute two queries, like so:

    Code:

    waypoints = Waypoint.where(:address => "Berlin").only(:offer_id).all
    offer_ids = waypoints.map(&:offer_id)
    offers = Offer.any_in(:_id => offer_ids).all
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with an application hanging and giving me the default Please
I'm having a problem writing Norwegian characters into an XML file using C#. I
I have a Gridview that displays paged results from a search query. The problem
I am having a problem with a FreeText search, currently running on a SQL
I am using the entity framework and I'm having a problem with re-finding objects
Having a small problem for a quick Search and Highlight script that I'm working
I'm using ruby 1.9.2 and rails 3 and I think I'm having a moderately
I'm having a problem with my app-engine queries. When I run my query without
I'm having some problems with the ranking used by fulltext search in SQL Server.
We're having problem with a huge number of legacy stored procedures at work. Do

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.