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.