Skip to content

Is there a way to select columns on two left joined tables use BaseQuery? #1893

Answered by zw963
zw963 asked this question in Q&A
Discussion options

You must be logged in to vote

Hi, @jwoertink , in fact, i figure out how to solve my issue after fight with it one day, i don't want to select column in two table, i just don't know how to OR query on two table columns

following is the the expected answer.

user_chong_wen_bao_query = ChongWenBaoQuery.new.user_id(current_user.id)
query = UniversityQuery.new.preload_chong_wen_baos(user_chong_wen_bao_query)

    query = query.where("(name &@~ ?", q)
                .or(
                  &.where_chong_wen_baos(
                    ChongWenBaoQuery.new.where("chong_wen_baos.university_remark &@~ ?)", q),
                    auto_inner_join: false
                  ).left_join_chong_wen_baos
                )

As you can see…

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@zw963
Comment options

Comment options

You must be logged in to vote
1 reply
@zw963
Comment options

Answer selected by zw963
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants