Jack Danger Canty
2007-Sep-29 02:52 UTC
Using hash conditions with explicit table name (#9733)
Ahoy! Have you guys ever needed to do this?: Post.find(:all, ;include => :comments, :conditions => {''comments.created_at'' => 14.days.ago..7.days.ago}) Well, I certainly have. And I finally got around to patching sanitize_sql_hash_for_conditions() so rather than doing this: "SELECT ... WHERE posts.`comments.created_at` BETWEEN ..." it provides us with: "SELECT ... WHERE comments.created_at BETWEEN ..." And you can have the whole package for the low, low price of a +1. http://dev.rubyonrails.org/ticket/9733 ::Jack Danger --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jeffrey Hardy
2007-Sep-29 13:58 UTC
Re: Using hash conditions with explicit table name (#9733)
+1 On 28-Sep-07, at 10:52 PM, Jack Danger Canty wrote:> Ahoy! > > Have you guys ever needed to do this?: > > Post.find(:all, ;include => :comments, :conditions => > {''comments.created_at '' => 14.days.ago..7.days.ago}) > > Well, I certainly have. And I finally got around to patching > sanitize_sql_hash_for_conditions() so rather than doing this: > "SELECT ... WHERE posts.`comments.created_at` BETWEEN ..." > it provides us with: > "SELECT ... WHERE comments.created_at BETWEEN ..." > > > And you can have the whole package for the low, low price of a +1. > > http://dev.rubyonrails.org/ticket/9733 > > ::Jack Danger > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Sep-29 23:39 UTC
Re: Using hash conditions with explicit table name (#9733)
I was thinking about this recently, but was toying around with a different, possibly more flexible syntax... :conditions => {:comments => {:created_at '' => 14.days.ago..7.days.ago}} Combined with normal conditions... :conditions => {:field => value, :comments => {:created_at '' => 14.days.ago..7.days.ago}} You could nest as deep as you like in the same way :include works. Any issues with this approach instead? Andrew On 9/28/07, Jack Danger Canty <dangeronrails@gmail.com> wrote:> Ahoy! > > Have you guys ever needed to do this?: > > Post.find(:all, ;include => :comments, :conditions => {''comments.created_at > '' => 14.days.ago..7.days.ago}) > > Well, I certainly have. And I finally got around to patching > sanitize_sql_hash_for_conditions() so rather than doing > this: > "SELECT ... WHERE posts.`comments.created_at` BETWEEN ..." > it provides us with: > "SELECT ... WHERE comments.created_at BETWEEN ..." > > > And you can have the whole package for the low, low price of a +1. > > http://dev.rubyonrails.org/ticket/9733 > > ::Jack Danger > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Carlos Henrique Palhares
2007-Sep-30 04:58 UTC
Re: Using hash conditions with explicit table name (#9733)
This suggestion seems to be a little bit more "ruby way" and tends to organize the code a bit more... On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote:> > > I was thinking about this recently, but was toying around with a > different, possibly more flexible syntax... > > :conditions => {:comments => {:created_at '' => 14.days.ago..7.days.ago}} > > Combined with normal conditions... > > :conditions => {:field => value, :comments => {:created_at '' => > 14.days.ago..7.days.ago}} > > You could nest as deep as you like in the same way :include works. > > Any issues with this approach instead? > > Andrew > > On 9/28/07, Jack Danger Canty <dangeronrails@gmail.com> wrote: > > Ahoy! > > > > Have you guys ever needed to do this?: > > > > Post.find(:all, ;include => :comments, :conditions => {'' > comments.created_at > > '' => 14.days.ago..7.days.ago}) > > > > Well, I certainly have. And I finally got around to patching > > sanitize_sql_hash_for_conditions() so rather than doing > > this: > > "SELECT ... WHERE posts.`comments.created_at` BETWEEN ..." > > it provides us with: > > "SELECT ... WHERE comments.created_at BETWEEN ..." > > > > > > And you can have the whole package for the low, low price of a +1. > > > > http://dev.rubyonrails.org/ticket/9733 > > > > ::Jack Danger > > > > > > > > >-- Carlos Palhares JĂșnior carlos@milk-it.net +55 (31) 8763-5606 Milk-it Brasil Software House -- "If you have any great suggestions, feel free to mail me, and I''ll probably feel free to ignore you." Linus Torvalds --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jack Danger Canty
2007-Sep-30 05:44 UTC
Re: Using hash conditions with explicit table name (#9733)
On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote:> > > I was thinking about this recently, but was toying around with a > different, possibly more flexible syntax... > > :conditions => {:comments => {:created_at '' => 14.days.ago..7.days.ago}}That''s way better! Care to write a patch? ::Jack Danger --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Sep-30 05:50 UTC
Re: Using hash conditions with explicit table name (#9733)
Almost done. :) On 9/30/07, Jack Danger Canty <dangeronrails@gmail.com> wrote:> > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > I was thinking about this recently, but was toying around with a > > different, possibly more flexible syntax... > > > > :conditions => {:comments => {:created_at '' => 14.days.ago..7.days.ago}} > > > That''s way better! Care to write a patch? > > ::Jack Danger > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Sep-30 06:28 UTC
Re: Using hash conditions with explicit table name (#9733)
I mentioned nesting to any depth before (just off the top of my head), but I''m not sure if that''s useful or not... Doing this... Post.find(:all, ;include => {:comments => :users}, :conditions => {:comments => {:users => {:name => ''Joe''}, :created_at => 14.days.ago..7.days.ago}}) would be the same thing as... Post.find(:all, ;include => {:comments => :users}, :conditions => {:comments => {:created_at => 14.days.ago..7.days.ago}, :users => {:name => ''Joe''}}) resulting in... comments.created_at BETWEEN ... AND users.name = ''Joe'' My patch does work with conditions to any depth, but is it useful? I suppose it could make things look cleaner as to better match the style of the :include and there might be other styles or uses that I can''t think of at the moment. My patch right now is recursive which allows the extra depth, but if that''s not seen as useful, I''ll rewrite it with an iterative approach and not allow the extra depth. Andrew On 9/30/07, Andrew Kaspick <akaspick@gmail.com> wrote:> Almost done. :) > > On 9/30/07, Jack Danger Canty <dangeronrails@gmail.com> wrote: > > > > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > > > I was thinking about this recently, but was toying around with a > > > different, possibly more flexible syntax... > > > > > > :conditions => {:comments => {:created_at '' => 14.days.ago..7.days.ago}} > > > > > > That''s way better! Care to write a patch? > > > > ::Jack Danger > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Jack Danger Canty
2007-Sep-30 06:37 UTC
Re: Using hash conditions with explicit table name (#9733)
On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote:> > > I mentioned nesting to any depth before (just off the top of my head), > but I''m not sure if that''s useful or not...I don''t think we''ll need the extra depth, just :conditions => {:table => {:column => ''value''}} should suffice. I can''t think of any complication beyond that that would be useful. It should be as simple as checking whether the given value is a hash - no recursion should be necessary. ::Jack Danger Doing this...> > Post.find(:all, ;include => {:comments => :users}, :conditions => > {:comments => {:users => {:name => ''Joe''}, :created_at => > 14.days.ago..7.days.ago}}) > > would be the same thing as... > > Post.find(:all, ;include => {:comments => :users}, :conditions => > {:comments => {:created_at => 14.days.ago..7.days.ago}, :users => > {:name => ''Joe''}}) > > resulting in... > > comments.created_at BETWEEN ... AND users.name = ''Joe'' > > My patch does work with conditions to any depth, but is it useful? I > suppose it could make things look cleaner as to better match the style > of the :include and there might be other styles or uses that I can''t > think of at the moment. > > My patch right now is recursive which allows the extra depth, but if > that''s not seen as useful, I''ll rewrite it with an iterative approach > and not allow the extra depth. > > Andrew > > On 9/30/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > Almost done. :) > > > > On 9/30/07, Jack Danger Canty <dangeronrails@gmail.com> wrote: > > > > > > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > > > > > I was thinking about this recently, but was toying around with a > > > > different, possibly more flexible syntax... > > > > > > > > :conditions => {:comments => {:created_at '' => > 14.days.ago..7.days.ago}} > > > > > > > > > That''s way better! Care to write a patch? > > > > > > ::Jack Danger > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Sep-30 07:25 UTC
Re: Using hash conditions with explicit table name (#9733)
I uploaded my patch to http://dev.rubyonrails.org/ticket/9733, but kept the recursive approach. My brain found it to be easiest and cleanest to implement it that way. :) If you want to redo it with an iterative approach, please feel free. Regards, Andrew On 9/30/07, Jack Danger Canty <dangeronrails@gmail.com> wrote:> > > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > I mentioned nesting to any depth before (just off the top of my head), > > but I''m not sure if that''s useful or not... > > I don''t think we''ll need the extra depth, just :conditions => {:table => > {:column => ''value''}} should suffice. I can''t think of any complication > beyond that that would be useful. > > It should be as simple as checking whether the given value is a hash - no > recursion should be necessary. > > ::Jack Danger > > > Doing this... > > > > Post.find(:all, ;include => {:comments => :users}, :conditions => > > {:comments => {:users => {:name => ''Joe''}, :created_at => > > 14.days.ago..7.days.ago}}) > > > > would be the same thing as... > > > > Post.find(:all, ;include => {:comments => :users}, :conditions => > > {:comments => {:created_at => 14.days.ago..7.days.ago}, :users => > > {:name => ''Joe''}}) > > > > resulting in... > > > > comments.created_at BETWEEN ... AND users.name = ''Joe'' > > > > My patch does work with conditions to any depth, but is it useful? I > > suppose it could make things look cleaner as to better match the style > > of the :include and there might be other styles or uses that I can''t > > think of at the moment. > > > > My patch right now is recursive which allows the extra depth, but if > > that''s not seen as useful, I''ll rewrite it with an iterative approach > > and not allow the extra depth. > > > > Andrew > > > > On 9/30/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > Almost done. :) > > > > > > On 9/30/07, Jack Danger Canty < dangeronrails@gmail.com> wrote: > > > > > > > > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > > > > > > > I was thinking about this recently, but was toying around with a > > > > > different, possibly more flexible syntax... > > > > > > > > > > :conditions => {:comments => {:created_at '' => > 14.days.ago..7.days.ago}} > > > > > > > > > > > > That''s way better! Care to write a patch? > > > > > > > > ::Jack Danger > > > > > > > > > > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---
Andrew Kaspick
2007-Sep-30 21:23 UTC
Re: Using hash conditions with explicit table name (#9733)
This ticket (http://dev.rubyonrails.org/ticket/9733) has a couple of +1''s for the previous string style, but I guess we need some new +1''s for my updated hash style. +1 away if you see no issues. Andrew On 9/30/07, Andrew Kaspick <akaspick@gmail.com> wrote:> I uploaded my patch to http://dev.rubyonrails.org/ticket/9733, but > kept the recursive approach. My brain found it to be easiest and > cleanest to implement it that way. :) > > If you want to redo it with an iterative approach, please feel free. > > Regards, > Andrew > > On 9/30/07, Jack Danger Canty <dangeronrails@gmail.com> wrote: > > > > > > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > > > I mentioned nesting to any depth before (just off the top of my head), > > > but I''m not sure if that''s useful or not... > > > > I don''t think we''ll need the extra depth, just :conditions => {:table => > > {:column => ''value''}} should suffice. I can''t think of any complication > > beyond that that would be useful. > > > > It should be as simple as checking whether the given value is a hash - no > > recursion should be necessary. > > > > ::Jack Danger > > > > > Doing this... > > > > > > Post.find(:all, ;include => {:comments => :users}, :conditions => > > > {:comments => {:users => {:name => ''Joe''}, :created_at => > > > 14.days.ago..7.days.ago}}) > > > > > > would be the same thing as... > > > > > > Post.find(:all, ;include => {:comments => :users}, :conditions => > > > {:comments => {:created_at => 14.days.ago..7.days.ago}, :users => > > > {:name => ''Joe''}}) > > > > > > resulting in... > > > > > > comments.created_at BETWEEN ... AND users.name = ''Joe'' > > > > > > My patch does work with conditions to any depth, but is it useful? I > > > suppose it could make things look cleaner as to better match the style > > > of the :include and there might be other styles or uses that I can''t > > > think of at the moment. > > > > > > My patch right now is recursive which allows the extra depth, but if > > > that''s not seen as useful, I''ll rewrite it with an iterative approach > > > and not allow the extra depth. > > > > > > Andrew > > > > > > On 9/30/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > Almost done. :) > > > > > > > > On 9/30/07, Jack Danger Canty < dangeronrails@gmail.com> wrote: > > > > > > > > > > On 9/29/07, Andrew Kaspick <akaspick@gmail.com> wrote: > > > > > > > > > > > > I was thinking about this recently, but was toying around with a > > > > > > different, possibly more flexible syntax... > > > > > > > > > > > > :conditions => {:comments => {:created_at '' => > > 14.days.ago..7.days.ago}} > > > > > > > > > > > > > > > That''s way better! Care to write a patch? > > > > > > > > > > ::Jack Danger > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com To unsubscribe from this group, send email to rubyonrails-core-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en -~----------~----~----~----~------~----~------~--~---