I have some tables: users, posts, translations, vocabularies a user can create posts, make translations for words on posts and can mark translations of others as vocabularies for review. table vocabularies only has 2 columns (user_id,translation_id) In controller I declare variable:
@translations = @post.translations.where("translations.words=?", params[:words], params[:end]).joins("LEFT OUTER JOIN vocabularies ON vocabularies.translation_id = translations.id AND vocabularies.user_id = 6").select("translations.*")
And get errors
SQLite3::SQLException: near "*": syntax error: SELECT COUNT(translations.*) FROM "translations" LEFT OUTER JOIN vocabularies ON vocabularies.translation_id = translations.id AND vocabularies.user_id = 6 WHERE "translations"."post_id" = ? AND (translations.words='hello')
One more question, because the :translations and :vocabularies both have the same column user_id, so how can alias user_id of :vocabularies as learner_id? I tried to run this command but it still got error: SQLite3::SQLException: near "as":
@translations = @post.translations.where("translations.words=?", params[:words], params[:end]).joins("LEFT OUTER JOIN vocabularies ON vocabularies.translation_id = translations.id AND vocabularies.user_id = 6").select("translations.*, vocabularies.user_id as learner_id")
Please help me out. Thank you.
@post.translations.joins(:vocabularies).where(words: params[:words] + params[:end], vocabularies: {user_id: 6})and add the select at the end