Skip to content
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

Make Mobility::Plugins::ActiveRecord::Query::VirtualRow public #471

Merged
merged 7 commits into from
Dec 19, 2020

Conversation

shioyama
Copy link
Owner

@shioyama shioyama commented Dec 12, 2020

There should be a way to build queries without using the query scope. This PR makes this more easily possible by making Mobility::Plugins::ActiveRecord::Query::VirtualRow public, and also adding a class method Query.build_query which can be used like this:

Mobility::Plugins::ActiveRecord::Query.build_query(Post) do
  title.eq('foo')
end

This is equivalent to:

Post.i18n do
  title.eq('foo')
end

The namespace is cumbersome but you can just name it something else in your application:

I18nQueryScope = Mobility::Plugins::ActiveRecord::Query

then use:

I18nQueryScope.build_query(Post) do
  title.eq('foo')
end

@sedubois
Copy link
Contributor

There should be a way to build queries without using the query scope

Thank you @shioyama, what does Mobility::Plugins::ActiveRecord::Query.build_query(Post) improve compared to Post.i18n?

@shioyama
Copy link
Owner Author

what does Mobility::Plugins::ActiveRecord::Query.build_query(Post) improve compared to Post.i18n?

Not a whole lot, but it takes away the requirement to define a class method (i18n) on the model. Internally, code can avoid depending on that method and instead reference Mobility::Plugins::ActiveRecord::Query.build_query.

Since the method name is configurable other plugins and gems shouldn't rely on the method name, so this would provide a "safe" way to get the same functionality.

@shioyama shioyama merged commit c0364c3 into master Dec 19, 2020
@github-pages github-pages bot temporarily deployed to github-pages December 19, 2020 06:45 Inactive
@shioyama shioyama deleted the make_virtual_row_public branch December 21, 2020 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants