Cool! I think the hard work is already done. But I still find it hard to
justify this in the framework. It is a feature that is out of Rails for
more than 10 years and I personally never needed it working in many
applications through the years so I'm not sure if I want to add that
complexity to the framework and maintain this feature.

We are planing to expose arel as public API sometime in the future so maybe
that would be enough to allow people who wants to use CTE to be able to use
in their application.

Rafael Mendonça França
http://twitter.com/rafaelfranca
https://github.com/rafaelfranca


On Tue, Jan 15, 2019 at 7:41 PM Sean Linsley <sean.ian.lins...@gmail.com>
wrote:

> While we’re on the subject, I have a PR to get postgres_ext working with
> Rails 5.2, but need help from someone that has experience with Arel’s
> internals.
>
> https://github.com/danmcclain/postgres_ext/pull/2
>
> Though more broadly I’m of the opinion that most of it should be inlined
> into Rails, and would be happy to work on that effort if it’s welcome.
>
> On Jan 15, 2019, at 6:37 PM, Daniel Heath <daniel.r.he...@gmail.com>
> wrote:
>
> https://rubygems.org/gems/postgres_ext implements this for rails up to
> version 4, and has ~2 million downloads.
>
> https://github.com/kmurph73/ctes_in_my_pg ports the code to rails 5.
>
> There are also numerous blog posts around documenting how to work around
> the issue by dropping down to raw Arel or string interpolation.
>
> eg:
>  *
> http://www.scimedsolutions.com/articles/75-arel-part-ii-common-table-expressions
>  * https://hashrocket.com/blog/posts/recursive-sql-in-activerecord
>  *
> https://sonnym.github.io/2017/06/05/common-table-expressions-in-activerecord-a-case-study-of-quantiles/
>
>
>
> https://www.cockroachlabs.com/blog/cockroachdb-hearts-activerecord-ruby-on-rails/
> also mentions that ActiveRecord uses CTEs internally.
>
> Would you agree that's a suitable level of usage to justify including this
> SQL-99 feature in core ActiveRecord? Or is the complexity likely to be too
> much for the number of users affected?
>
> Thanks,
>
> Daniel Heath
>
> On Wednesday, January 16, 2019 at 11:21:42 AM UTC+11, Rafael Mendonça
> França wrote:
>>
>> Thank you for the feature proposal. It doesn't seem to be difficult to
>> implement this as a gem given most of the APIs you need in able to
>> implement something like this are public.
>>
>> What do you think about implementing this first as a gem and see if there
>> are adoption of this feature before proposing adding to the rails framework?
>>
>> Thanks.
>>
>> Rafael Mendonça França
>> http://twitter.com/rafaelfranca
>> https://github.com/rafaelfranca
>>
>>
>> On Tue, Jan 15, 2019 at 7:12 PM Daniel Heath <daniel....@gmail.com>
>> wrote:
>>
>>> I'd like to be able to use my ActiveRecord scopes in a CTE for another
>>> scope.
>>>
>>> Proposed syntax
>>>
>>>
>>> class Post < ActiveRecord::Base
>>> has_many :comments
>>> end
>>>
>>> class Comment < ActiveRecord::Base
>>> belongs_to :post
>>> end
>>>
>>> Post.with(Comment.select(:post_id), name: :post_ids, recursive:
>>> false).where(id: {post_ids: :post_id})
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> Would a patch supporting this syntax be accepted?
>>>
>>> Thanks,
>>>
>>> Daniel Heath
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Ruby on Rails: Core" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to rubyonrails-co...@googlegroups.com.
>>> To post to this group, send email to rubyonra...@googlegroups.com.
>>> Visit this group at https://groups.google.com/group/rubyonrails-core.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-core+unsubscr...@googlegroups.com.
> To post to this group, send email to rubyonrails-core@googlegroups.com.
> Visit this group at https://groups.google.com/group/rubyonrails-core.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to