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

How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229