What is a difference between belongs_to and has_one?

How can I decide belongs_to use to X(assume) model and has_one use to
Y(assume) model?

Kind regards.

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5d38e361d4f84b0638354b02d054534e%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

  • Colin Law at Jun 30, 2014 at 2:24 pm

    On 30 June 2014 14:45, Jaimin Pandya wrote:
    What is a difference between belongs_to and has_one?
    They are at opposite ends of the association. The model that
    belongs_to is the one that has the Y_id field in the database.
    How can I decide belongs_to use to X(assume) model and has_one use to
    Y(assume) model?
    Do you mean how to decide whether X belongs_to Y and Y has_one X
    versus Y belongs_to X and X has_one Y? If so then it is just a matter
    of which seems to fit best for you. Of course a third alternative is
    to simplify the code and the database and combine the models into XY.

    Colin

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuEfV%2B1ehaN6PEp3KbNL066QHZJh1_JyFUHzJaxCVLbMQ%40mail.gmail.com.
    For more options, visit https://groups.google.com/d/optout.
  • Jaimin Pandya at Jul 8, 2014 at 3:51 pm

    Colin Law wrote in post #1151152:
    On 30 June 2014 14:45, Jaimin Pandya wrote:
    What is a difference between belongs_to and has_one?
    They are at opposite ends of the association. The model that
    belongs_to is the one that has the Y_id field in the database.
    How can I decide belongs_to use to X(assume) model and has_one use to
    Y(assume) model?
    Do you mean how to decide whether X belongs_to Y and Y has_one X
    versus Y belongs_to X and X has_one Y? If so then it is just a matter
    of which seems to fit best for you. Of course a third alternative is
    to simplify the code and the database and combine the models into XY.
    Thank you for your reply.

    I am looking for difference which is explained by following link:

      http://stackoverflow.com/questions/861144/difference-between-has-one-and-belongs-to-in-rails

    --
    Posted via http://www.ruby-forum.com/.

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/eadeee0e2e3bbc2cb107455c09a52bec%40ruby-forum.com.
    For more options, visit https://groups.google.com/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJun 30, '14 at 1:46p
activeJul 8, '14 at 3:51p
posts3
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Jaimin Pandya: 2 posts Colin Law: 1 post

People

Translate

site design / logo © 2022 Grokbase