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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:08:26+00:00 2026-06-14T06:08:26+00:00

I have a small app that allows users to upload recipes and save favourite

  • 0

I have a small app that allows users to upload recipes and save favourite recipes. I have a separate model called country that has all the countries of the world within it which then allows users to select one from a dropdown.

Initially I had the association as

recipe

has_one :country

country

belongs_to :recipe

After some research the correct association is

recipe

belongs_to :country

country

belongs_to :recipe

The foreign key country_id going within the recipe model.

I’m going to do some more reading but was wondering if someone could explain as to why it is this association and not the first one

  • 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-14T06:08:27+00:00Added an answer on June 14, 2026 at 6:08 am

    I guest you want to build association like this:

    • country can has many recipe
    • recipe belongs to one country

    If so, you should define association is:

    country:

    has_many :recipes
    

    recipe:

    belongs_to :country
    

    And i think your second association is also incorrect.

    When you define belongs_to :country in Recipe model, it means your Recipe table must have a column called country_id. It is a foreign key to Country model.

    In the first define association, the Country model will have a column called recipe_id, so, every country just has only one recipe, that’s not what you want, right? Why it’s not work? Because with one country you have only one record, so one country can have only one recipe, accessed through recipe_id.

    With first association, your association is One-to-One (One Country has one Recipe), while you actually want your association is One-to-Many ( One Country has Many Recipe). So it’s reason why first association not works (second too).

    The main thing you need to remember here is, what model you put a belongs_to association, that model will have a column called 'association name'_id. The different between using has_one and belongs_to only is where you put foreign key and the meaning of association. Check here to clearer.

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

Sidebar

Related Questions

I have developed a small web app. This app allows users to upload images.
I have a small tab on an app that allows user to lookup a
I have a small app that allows the user to draw on the screen
I'm building an app in Rails that allows users to upload images to their
I am making a small web app that allows users to submit html, css
I have a small cakePHP app that allows for user's to login and be
I am working on a small app that allows for users to add a
I have a small APP which allows users to view information on Beers and
I have small web app that generate PDF files as a report. I'm trying
I have a small app that downloads some files from a remote (HTTP) server

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.