I resolved my problem, I just did
Quiz.where(title: /#{query}/i).or(id: Question.where(title: /#{query}/i).
select(:quiz_id))
This seems much better than joining, for this particular problem. I'm still
curious about the above table priority in joins, though.
On Saturday, March 14, 2015 at 11:40:18 AM UTC+1, Janko Marohnić wrote:
>
> I'm fairly new to Sequel, but I had a lot of experience with ActiveRecord.
>
> I have Quiz model, which has many Questions. I'm trying to do a search
> which returns quizzes, but which also searches associated questions (I
> know, the basics :P). Now, I'm really impressed with Sequel's joins,
> ActiveRecord really sucks when it comes to joins. So, I have something like
> this:
>
> Quiz.association_right_join(:questions).to_a
> # => [#<Quiz @values={:id=>73, :quiz_id=>152, ...>]
>
> What happens is that columns are kind of joined together, which I
> understand. But what I find strange is that questions take over, and
> quizzes retreat ("id" becomes "quiz_id"). I find this strange, because if
> I'm searching *quizzes*, shouldn't *questions* be the second-class
> citizens (that questions' "id" turn into "question_id")?
>
> Also, is it possible to disable joining values? Because I only want to do
> a query, I don't need questions' columns. Maybe a "where" subquery would be
> better for that, without joining? How would I write it?
>
> Thanks,
> Janko
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.