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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:50:16+00:00 2026-05-25T20:50:16+00:00

I have two models, Foo and Bar, with same attributes, and I’m ‘caching’ user

  • 0

I have two models, Foo and Bar, with same attributes, and I’m ‘caching’ user “search params” into a session variable, that ends into something like this:

session[:search_params] => {"price"=>"15.0", "air_conditioner"=>"0", "fireplace"=>"0", "number_of_rooms"=>"1", "balcony"=>"0"} 

I’d like to search both Foo and Bar for entries that match this query.

For now, I’m doing:

@foo = Foo.new(session[:search_params])
search_attributes = @foo.attributes
search_attributes.delete 'id'
search_attributes.delete 'created_at'
search_attributes.delete 'updated_at'
@results = Foo.where(search_attributes)
@results += Bar.where(search_attributes)

that is REALLY UGLY.

Could anyone tell me a better/the correct way?

Thanks in advance.

EDIT

Also, some params in the session[:search_params] that are “0”, are actually ‘false’ on the database (booleans) (filled by checkboxes), so I have to do some “conversion” into this fields so that the query is done correctly, i.e., getting for example air_conditioner => 'false' instead of air_conditioner => '0'.

  • 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-25T20:50:17+00:00Added an answer on May 25, 2026 at 8:50 pm

    I wouldn’t follow that path if I were you. I would go with a solution like https://github.com/ernie/meta_search

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

Sidebar

Related Questions

I have two models: class Foo(models.Model): foo_field = ... class Bar(models.Model): foo = models.ForeignKey(Foo,
I have two models: Bar HABTM Foo. Now I have bars_foos join table with
I have two models, Foo and Bar . Bar has a foreign key to
Given two model classes, Foo and Bar , I want Foo to have 3
I have two models indexed for searching (User and Item). I'm trying to do
I have two models in my Django application, for the purposes of storing search
I have two models, user and group. I also have a joining table groups_users.
I have two entities Foo and Bar with a Many to Many relationship between
Let's say my app has two models, Foo and Bar. Foo optionally belongs_to Bar.
I have two classes, Foo and Bar, in a Django app (on AppEngine if

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.