I have been checking your website for more has_many :through articles.
I have this question which I hope you could provide your insights, as I have been checking around but to-date still could not fully understand.
I would greatly appreciate if you could look at my code on http://railsforum.com/viewtopic.php?id=10204
I have these 2 tables: groups and users, where a group can have many users and an user can have many groups.
I have this third table, roles, which contains group_id, user_id, type. The field 'type' can be Administrator, Owner and Member. A user can play the role of Owner for a group but assume the role of member for another group. I use this table as Single Table Inheritance.
I want to do such query:
Based on a given user's id, I want to
display all the groups of this user, with the respective role for that group.
I have been reading and trying the associations. The last working association I tried is (assuming the user-id I want to check is 1):
User.find(1).roles.each do |role|
<%= role.group.name %>
end
Is that the way to perform such query?
Thank you, for your great effort in sharing your knowledge with others.
Thank you for this Railscast. Your work is slowly helping me understand the more interesting side of rails.
The on issue I felt would have been nice here would be how to use the @accounts in your view. This would have complete the information needed to create the HABTM. I.E. if we had a user with an account and wanted to pull up the account for the user as a view, how would one use this?
This is very interesting . you can learn Course Training of Digital Marketing Training at Digital Marketing Training institute by Google Adwords PPC management Company and also avail Google Adwords PPC Service or call at Customer Service Phone Number
will this work if you have @projects, i.e multiple projects?
@bob, nope. If you have an array of projects you'll have to fetch the tasks for all those projects using a custom find of some sort.
Hi Ryan,
I have been checking your website for more has_many :through articles.
I have this question which I hope you could provide your insights, as I have been checking around but to-date still could not fully understand.
I would greatly appreciate if you could look at my code on http://railsforum.com/viewtopic.php?id=10204
I have these 2 tables: groups and users, where a group can have many users and an user can have many groups.
I have this third table, roles, which contains group_id, user_id, type. The field 'type' can be Administrator, Owner and Member. A user can play the role of Owner for a group but assume the role of member for another group. I use this table as Single Table Inheritance.
I want to do such query:
Based on a given user's id, I want to
display all the groups of this user, with the respective role for that group.
I have been reading and trying the associations. The last working association I tried is (assuming the user-id I want to check is 1):
User.find(1).roles.each do |role|
<%= role.group.name %>
end
Is that the way to perform such query?
Thank you, for your great effort in sharing your knowledge with others.
Thank you very much.
Is this really a Find Through Association or a has_many / belongs_to.
What about a many to many 'find through' association?
Thank you for this Railscast. Your work is slowly helping me understand the more interesting side of rails.
The on issue I felt would have been nice here would be how to use the @accounts in your view. This would have complete the information needed to create the HABTM. I.E. if we had a user with an account and wanted to pull up the account for the user as a view, how would one use this?
Thanks Again.
This episode has been updated to Rails 4.2 as an article Find Through Association.
Is this where you essentially cover off the old screencasts but with the newer syntax?
Thank you !
I have a ruby script based on fertilizer (engrais foliaire agricole et liquide en français) and thank's for your help.
Best regards,
Roselmark
This post previewed "2 comments"; is that because there have only been two comments in the last year?
This is very interesting . you can learn Course Training of Digital Marketing Training at Digital Marketing Training institute by Google Adwords PPC management Company and also avail Google Adwords PPC Service or call at Customer Service Phone Number
Thank you for this Railscast. Your work is slowly helping me understand the more interesting side of rails.
I like it
Dear your article is very nice and attractive. Keep sharing and have a great time blogging.
jempol kaki