Rails query not equal -


my rails app has 3 components: -users (has many works , comments) -works (blog posts) (belongs users, has many comments) -comments (comments belong both users , work)

i'm trying display comments on page particular user except comments made on blog posts belong him/her. should query in controller?

here have far. not load comments @ all.

    @user = user.find(params[:id])     @works = work.pluck(:user_id)     @comments = @user.comments.where(is_boolean_value: true).where(['user_id not in(?)', @works]).all 

how can change query shows comments made user user did not own work?

thanks! -b

the first problem

work.pluck(:user_id) 

that fetches user_id user has object of table work. instead, fetch work ids items user created:

@works = @user.works.map {|obj| obj.id} 

then ask database give comments belong user not belong 1 of works:

@comments = @user.comments.where('work_id not in(?)', @works) 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

java - Multi-Label Document Classification -

php - Dynamic url re-writing using htaccess -