Rails throwing error: Association named 'media' was not found on User; perhaps you misspelled it? -
So I'm trying to find all users who have made a comment under the same picture.
The psql terminal I write it and it gives me all the information that I need:
select * Come to the users, users.id = comments.user_id in the media Media to join .ID = Comments can include internal media. Media_id where media_id = 1
I am currently doing this in the rail:
@users = User.joins (: Comments: Media) .where (Media_id = @ medium.id)
I should work. But when trying to print all the usernames from my code in @
, this error is thrown:
The association named 'Media' Not found on user; Maybe you misspelled it?
Did I do wrong work in my pen?
DB Schema:
create_table "media", force: true do | T | # Unrecognized columns using t.integer "user_id" end add_index "media", ["user_id"], name: "index_media_on_user_id", :: btree create_table "comments", force: true do | T | # Indispensable column t.integer "user_id", null: false t.integer "media_id", empty: incorrect last add_index "comments", ["media_id"], name: "index_posts_on_media_id", using :: btree add_index " Comments ", [" User_id "], name:" index_posts_on_user_id ", using: btree create_table" users ", force: true do | T | T.string "name", default: "", null: false end
Associated with media
directly comments
with users
, you should:
@users = Users Joins (comment: media). Where (comment: {media_id: @ medium.id})
Comments
Post a Comment