Rails calling different fields in the same table The Next CEO of Stack OverflowCalling shell commands from RubyWhat's the difference between utf8_general_ci and utf8_unicode_ciA concise explanation of nil v. empty v. blank in Ruby on RailsUnderstanding the Rails Authenticity TokenHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How to drop columns using Rails migrationProblems with 2 relationships between 2 tables in the same column under Ruby on RailsWhat's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?Rails Engine: Namespacing foreign key references to other models in the same engine

Horror film about a man brought out of cryogenic suspension without a soul, around 1990

Avoiding the "not like other girls" trope?

Can I cast Thunderwave and be at the center of its bottom face, but not be affected by it?

Prodigo = pro + ago?

Why does freezing point matter when picking cooler ice packs?

Why did the Drakh emissary look so blurred in S04:E11 "Lines of Communication"?

Would a grinding machine be a simple and workable propulsion system for an interplanetary spacecraft?

Create custom note boxes

What did the word "leisure" mean in late 18th Century usage?

Calculating discount not working

Creating a script with console commands

How to implement Comparable so it is consistent with identity-equality

Variance of Monte Carlo integration with importance sampling

Does int main() need a declaration on C++?

Is it okay to majorly distort historical facts while writing a fiction story?

Masking layers by a vector polygon layer in QGIS

Is there a rule of thumb for determining the amount one should accept for of a settlement offer?

Why did Batya get tzaraat?

Is a linearly independent set whose span is dense a Schauder basis?

Another proof that dividing by 0 does not exist -- is it right?

What steps are necessary to read a Modern SSD in Medieval Europe?

What difference does it make matching a word with/without a trailing whitespace?

How does a dynamic QR code work?

Are British MPs missing the point, with these 'Indicative Votes'?



Rails calling different fields in the same table



The Next CEO of Stack OverflowCalling shell commands from RubyWhat's the difference between utf8_general_ci and utf8_unicode_ciA concise explanation of nil v. empty v. blank in Ruby on RailsUnderstanding the Rails Authenticity TokenHow can I rename a database column in a Ruby on Rails migration?How do I get the current absolute URL in Ruby on Rails?How to drop columns using Rails migrationProblems with 2 relationships between 2 tables in the same column under Ruby on RailsWhat's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN?Rails Engine: Namespacing foreign key references to other models in the same engine










0















I want to call different fields in the same table,



Assignedby != Openedby



I cannot call the user to which the topic is assigned



mysql users table



mysql issues table



show.html.erb screenshot



<p>
<strong>Assignedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>

<p>
<strong>Openedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>



class Issue < ApplicationRecord

belongs_to :project, foreign_key: :project_id, optional: true

belongs_to :user, foreign_key: :assignedby_id, optional: true

belongs_to :user, foreign_key: :openedby_id, optional: true

belongs_to :user, foreign_key: :closedby_id, optional: true

end









share|improve this question

















  • 1





    you cannot define several relations with the same name (in your case, user). You should name them like belongs_to :user_assigner, foreign_key: :assignedby_id, optional: true, class_name: 'User', belongs_to :user_opener, [...] etc etc

    – MrYoshiji
    Mar 8 at 19:17











  • @MrYoshiji you are damn fast :)

    – Muhammad Faisal Iqbal
    Mar 8 at 19:18











  • @MrYoshiji thank you :)

    – Ozgur SARIOGLAN
    Mar 8 at 19:21
















0















I want to call different fields in the same table,



Assignedby != Openedby



I cannot call the user to which the topic is assigned



mysql users table



mysql issues table



show.html.erb screenshot



<p>
<strong>Assignedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>

<p>
<strong>Openedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>



class Issue < ApplicationRecord

belongs_to :project, foreign_key: :project_id, optional: true

belongs_to :user, foreign_key: :assignedby_id, optional: true

belongs_to :user, foreign_key: :openedby_id, optional: true

belongs_to :user, foreign_key: :closedby_id, optional: true

end









share|improve this question

















  • 1





    you cannot define several relations with the same name (in your case, user). You should name them like belongs_to :user_assigner, foreign_key: :assignedby_id, optional: true, class_name: 'User', belongs_to :user_opener, [...] etc etc

    – MrYoshiji
    Mar 8 at 19:17











  • @MrYoshiji you are damn fast :)

    – Muhammad Faisal Iqbal
    Mar 8 at 19:18











  • @MrYoshiji thank you :)

    – Ozgur SARIOGLAN
    Mar 8 at 19:21














0












0








0








I want to call different fields in the same table,



Assignedby != Openedby



I cannot call the user to which the topic is assigned



mysql users table



mysql issues table



show.html.erb screenshot



<p>
<strong>Assignedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>

<p>
<strong>Openedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>



class Issue < ApplicationRecord

belongs_to :project, foreign_key: :project_id, optional: true

belongs_to :user, foreign_key: :assignedby_id, optional: true

belongs_to :user, foreign_key: :openedby_id, optional: true

belongs_to :user, foreign_key: :closedby_id, optional: true

end









share|improve this question














I want to call different fields in the same table,



Assignedby != Openedby



I cannot call the user to which the topic is assigned



mysql users table



mysql issues table



show.html.erb screenshot



<p>
<strong>Assignedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>

<p>
<strong>Openedby:</strong>
<%= @issue.user.try(:fullname) %>

</p>



class Issue < ApplicationRecord

belongs_to :project, foreign_key: :project_id, optional: true

belongs_to :user, foreign_key: :assignedby_id, optional: true

belongs_to :user, foreign_key: :openedby_id, optional: true

belongs_to :user, foreign_key: :closedby_id, optional: true

end






mysql ruby-on-rails ruby






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 8 at 19:14









Ozgur SARIOGLANOzgur SARIOGLAN

84




84







  • 1





    you cannot define several relations with the same name (in your case, user). You should name them like belongs_to :user_assigner, foreign_key: :assignedby_id, optional: true, class_name: 'User', belongs_to :user_opener, [...] etc etc

    – MrYoshiji
    Mar 8 at 19:17











  • @MrYoshiji you are damn fast :)

    – Muhammad Faisal Iqbal
    Mar 8 at 19:18











  • @MrYoshiji thank you :)

    – Ozgur SARIOGLAN
    Mar 8 at 19:21













  • 1





    you cannot define several relations with the same name (in your case, user). You should name them like belongs_to :user_assigner, foreign_key: :assignedby_id, optional: true, class_name: 'User', belongs_to :user_opener, [...] etc etc

    – MrYoshiji
    Mar 8 at 19:17











  • @MrYoshiji you are damn fast :)

    – Muhammad Faisal Iqbal
    Mar 8 at 19:18











  • @MrYoshiji thank you :)

    – Ozgur SARIOGLAN
    Mar 8 at 19:21








1




1





you cannot define several relations with the same name (in your case, user). You should name them like belongs_to :user_assigner, foreign_key: :assignedby_id, optional: true, class_name: 'User', belongs_to :user_opener, [...] etc etc

– MrYoshiji
Mar 8 at 19:17





you cannot define several relations with the same name (in your case, user). You should name them like belongs_to :user_assigner, foreign_key: :assignedby_id, optional: true, class_name: 'User', belongs_to :user_opener, [...] etc etc

– MrYoshiji
Mar 8 at 19:17













@MrYoshiji you are damn fast :)

– Muhammad Faisal Iqbal
Mar 8 at 19:18





@MrYoshiji you are damn fast :)

– Muhammad Faisal Iqbal
Mar 8 at 19:18













@MrYoshiji thank you :)

– Ozgur SARIOGLAN
Mar 8 at 19:21






@MrYoshiji thank you :)

– Ozgur SARIOGLAN
Mar 8 at 19:21













1 Answer
1






active

oldest

votes


















1














You cannot give all these belongs_to associations the same name, they need to be different, for example:



class Issue < ApplicationRecord
with_option optional: true do
belongs_to :project
belongs_to :assigner, class_name: 'User', foreign_key: :assignedby_id
belongs_to :creator, class_name: 'User', foreign_key: :openedby_id
belongs_to :closer, class_name: 'User', foreign_key: :closedby_id
end
end





share|improve this answer

























  • assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

    – MrYoshiji
    Mar 8 at 19:28











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069593%2frails-calling-different-fields-in-the-same-table%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














You cannot give all these belongs_to associations the same name, they need to be different, for example:



class Issue < ApplicationRecord
with_option optional: true do
belongs_to :project
belongs_to :assigner, class_name: 'User', foreign_key: :assignedby_id
belongs_to :creator, class_name: 'User', foreign_key: :openedby_id
belongs_to :closer, class_name: 'User', foreign_key: :closedby_id
end
end





share|improve this answer

























  • assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

    – MrYoshiji
    Mar 8 at 19:28















1














You cannot give all these belongs_to associations the same name, they need to be different, for example:



class Issue < ApplicationRecord
with_option optional: true do
belongs_to :project
belongs_to :assigner, class_name: 'User', foreign_key: :assignedby_id
belongs_to :creator, class_name: 'User', foreign_key: :openedby_id
belongs_to :closer, class_name: 'User', foreign_key: :closedby_id
end
end





share|improve this answer

























  • assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

    – MrYoshiji
    Mar 8 at 19:28













1












1








1







You cannot give all these belongs_to associations the same name, they need to be different, for example:



class Issue < ApplicationRecord
with_option optional: true do
belongs_to :project
belongs_to :assigner, class_name: 'User', foreign_key: :assignedby_id
belongs_to :creator, class_name: 'User', foreign_key: :openedby_id
belongs_to :closer, class_name: 'User', foreign_key: :closedby_id
end
end





share|improve this answer















You cannot give all these belongs_to associations the same name, they need to be different, for example:



class Issue < ApplicationRecord
with_option optional: true do
belongs_to :project
belongs_to :assigner, class_name: 'User', foreign_key: :assignedby_id
belongs_to :creator, class_name: 'User', foreign_key: :openedby_id
belongs_to :closer, class_name: 'User', foreign_key: :closedby_id
end
end






share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 8 at 19:34

























answered Mar 8 at 19:20









spickermannspickermann

61.4k75880




61.4k75880












  • assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

    – MrYoshiji
    Mar 8 at 19:28

















  • assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

    – MrYoshiji
    Mar 8 at 19:28
















assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

– MrYoshiji
Mar 8 at 19:28





assigned_user is contradictory with the foreign key, it seems the relation here is to point to the user who assigned it, not who is assigned to it

– MrYoshiji
Mar 8 at 19:28



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid …


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069593%2frails-calling-different-fields-in-the-same-table%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

Posting a File and Associated Data to a RESTful WebService preferably as JSON2019 Community Moderator ElectionREST URI convention - Singular or plural name of resource while creating itUploading both data and files in one form using Ajax?How do I upload a file with metadata using a REST web service?REST API - file (ie images) processing - best practicesSpring: JSON data and file in the same requestREST API Put large dataPosting a file and JSON data to Spring rest serviceRESTful Web Service Upload/Download Large Data With JSONREST API Design sending JSON data and a file to the api in same requestPost JSONArray to REST servicePUT vs. POST in RESTParsing values from a JSON file?JavaScript/jQuery to download file via POST with JSON dataHow do I upload a file with metadata using a REST web service?How to POST JSON data with Curl from Terminal/Commandline to Test Spring REST?Separate REST JSON API server and client?what's the correct way to send a file from REST web service to client?How do I write JSON data to a file?What is “406-Not Acceptable Response” in HTTP?REST API - file (ie images) processing - best practices

How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page