-
Notifications
You must be signed in to change notification settings - Fork 87
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
Column backend does not support pluck or select #275
Comments
I was actually thinking about this just a couple hours before you posted this issue. As it turns out, this is very easy to do now that querying has been refactored into a plugin. I already added The methods I think could be easily supported are any ones that accept an arel node, so e.g. |
No, in fact I'm not thinking any other AR method at the moment, I have another use case that pg_search_scope :by_title, against: :title pg_search_scope :by_title, against: Post.mobility_translated_attributes
# Post.mobility_translated_attributes returns [:title_en, :title_jp] |
I just pushed what I have to the add_new_query_methods branch, here is the commit: 9bff9b0 I lightly tested it and it seems to work, but if you want to work on it from there please go ahead! It needs a few simple specs as well. |
Here's the code change, to discuss: %w[select pluck group].each do |method_name|
define_method method_name do |*attrs|
i18n_keys, keys = attrs.partition(&@klass.method(:mobility_attribute?))
return super(*attrs) if i18n_keys.empty?
base = i18n_keys.inject(self) { |query, key|
@klass.mobility_backend_class(key).apply_scope(query, backend_node(key))
}
base.public_send(method_name, *(keys + i18n_keys.map(&method(:backend_node))))
end
end
end As you mentioned, similar to Basically, what this does it two things:
One thing I noticed is that the Table and KeyValue backends will default to using an INNER join here, which I think is not really appropriate (it will not include any results which have no translations in |
Merged #284, so this is now half-solved on the master branch. |
|
Released in 0.8.2, and supported on all backends. Let me know if you notice any issues. |
Sure, thanks for the support :) |
@shioyama seems this bug is back in |
Sorry @borisrorsvort you'll have to elaborate. There are specs for pluck and select now, so basic usage is guaranteed to work. If there is a problem please provide a failing test. |
Context
I'm using
column
backend strategy in mobility and I can perform queries based on my translated column usingfind_by
and evenwhere
but what intrigues me is thatselect
orpluck
does not know how to handle my column name.I'm not considering this a problem but in fact a feature not implemented, if there is an already approach to handle this I'm sorry for the issue but I really didn't find nothing about in docs and stackoverflow.
Expected Behavior
I expect mobility to handle my column name when I use
select
orpluck
methods.Actual Behavior
Possible Fix
The text was updated successfully, but these errors were encountered: