-
Notifications
You must be signed in to change notification settings - Fork 50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] SubQueries capabilities #46
Comments
This is the same as #42. The exact expression you're trying to do isn't currently implemented, but baby_squeel does have limited support for subqueries.
I'd be happy to accept a pull request. |
@rzane glad to help but it's the first time I am taking a look at baby_squeel. Squeel is completely broken for our 4.2 upgrade so am I looking for options since we were doing pretty heavy usage of Squeel Can you point me in the correct direction to try to understand how to start this PR? I am not familiar with this codebase and from my first look I was somewhat lost :( I am assuming that given our heavy usage of Squeel I'll be able to contribute to baby_squeel to cover our usage cases Thanks and hope you can guide me in the right direction |
I did a little investigation. Here's a gist of what I think it would take. class Arel::Nodes::TableAlias
def on(node)
table = BabySqueel::Table.new(self)
table.on(node)
end
end That'll get you part of the way there:
As you can see, it's not using the alias ( Notes:
|
But for your example #<Arel::Table:0x007fea780b0210 @name="posts", @engine=Post(id: integer, title: string, author_id: integer, published_at: datetime, parent_id: integer, created_at: datetime, updated_at: datetime), @columns=nil, @aliases=[], @table_alias=nil, @primary_key=nil> Its not related to I am probably missing something that is in my face |
@danielnc I got this sort of working, but binds parameters don't work. |
@rzane thanks I am investigating missing bind params and I believe its related to this: rails/arel#363 Still trying to learn more about AREL to see what needs to be done to use bind params correctly |
I think the bind values have to be copied from the relation you're joining to the parent relation. At one time, baby_squeel had to handle this sort of thing for normal joins 7ca9e32. It's definitely not an issue with Active Record or with Arel. It's just that Arel is a private API within Rails, so |
Yes, problem is I don't have a ActiveRecord relation when calling |
Yes, that's true. Might have to implement a method on the DSL to handle the relation
|
I got bind_values working following your suggestion Any advice on how to properly handle where.has a.name? |
Yeah, you're right about baby_squeel/lib/baby_squeel/table.rb Lines 115 to 116 in a290e41
|
I am migrating from sqeel to baby_squeel (thanks for all the work!) and I came across a little issue during migration. I have master scope which selects from some huge table and then I do some filtering on it. I have a situation (multiple times in this project) where I need to reference the master table from the subquery and it throws undefined column exception. Something like this: s = MasterList.where(...)
subquery = Address.where.has { address_id == master_list.address_id }
s.where { exists subquery } master_list is undefined in this case. It is defined in the final query though. I cannot find in documentation/wiki how exactly this translates to baby_sqeel, if it's possible at all. Any hints would be appreciated :-) |
Hey @noice, could you create a new issue? This one is tracking a pretty specific feature request. Plus, if you could fill out the issue template when you create the issue, that would be especially appreciated. I don't know what your schema looks like or how your models are associated, so without that information, it'll really, really difficult to help you. |
That was a quick response! :-) Of course, I've created minimalistic example and created new issue #88 . |
Issue
Is it possible to use baby_squeel to create subqueries similar to the ones we have on Squeel?
I cannot find any documentation on this and we are trying to move from Squeel to Baby Squeel due to several bugs related to polymorphic relations and bind values on subqueries
Thanks
Reproduction
The text was updated successfully, but these errors were encountered: