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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:45:59+00:00 2026-06-17T05:45:59+00:00

I am creating an app where businesses can get listed, and I would also

  • 0

I am creating an app where businesses can get listed, and I would also like to add a facility where they can specify which countries they export to. So when a user searches for listings of a business in their country, they not only see the businesses who are located in their country, but businesses in other countries that may to export their services to their country too.

Here’s my thoughts so far – any better solutions? I’m using Rails 3.2 and Postgres.

  • Country model, with fields for id, name, slug etc
  • Listing model, has a Postgres array field which stores the country ids that that business exports to

Then when I show listings for a country, I can just search for businesses that also have that country id in the country_export array.

But is this the most efficient way to do it? (I would use the postgres_ext gem to enable pg array support: https://github.com/dockyard/postgres_ext)

The other option I can think of is with checkboxes on the Listing model, so businesses can say whether they export worldwide, to the EU, to Asia, etc. Then add those as boolean fields on the country model. Downside to this is it won’t be as accurate as specifically stating the countries… but I wouldn’t mind the compromise if it is a more efficient way to go about it.

  • 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-17T05:46:00+00:00Added an answer on June 17, 2026 at 5:46 am

    This is a classical n:m relationship between the two tables company and country, which is normally implemented by a table (like company_country) referring to the two primary keys of those tables.

    See full code examples under these closely related questions:
    How to implement a many-to-many relationship in PostgreSQL?
    Many-to-many relation filter

    For a list of companies in a certain country your query would be:

    SELECT c.*
    FROM   company_country cc
    JOIN   company c USING (company_id)
    WHERE  cc.country_id = ?
    

    Relational database basics, SQL basics. With proper indexes, this is much faster than handling arrays.

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

Sidebar

Related Questions

I am creating a rails app which will help out businesses. These businesses have
i am creating app which would download and save files, than user could use
Hi i'm creating an app which have shopping cart and payment done via paypal
I'm creating an app that I want to license out to businesses on a
I'm creating an app for a local business, but they're making it a pain
I'm building an app that provides functionality for both consumers and businesses. In creating
We'd like to see if we can get some improved performance for analysis and
I am creating a web app for a business which includes several departments. I
I'm creating app which uses very large amount of memory. When I finish computation
I'm creating a MonoTouch app that has some declarative business logic that the client

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.