On Thursday, May 23, 2013 1:59:40 AM UTC-3, Gary Weaver wrote:
> Just noticed I messed up earlier because was copying/pasting and didn't
> see that 31,32310512 were comma-separated values. I was looking at it as a
> decimal- I need to get my eyes checked (or my European decimal notation
> interpreter turned off).
>
> How about:
>
> a = [[1,2],[3,4]]
> Phone.where("(ddd, number) in (#{(['(?, ?)']*a.size).join(', ')})", *a)
>
> That should work. Sorry, I should have gone back and looked more
> carefully. But probably best to take this discussion off of the Rails core
> list.
Why take it off rails core? Isn't the discussion whether where('(?)',
[[1,2],[3,4]]) should expand to ((1,2),(3,4)) or not be here?
Just like I rather write Phone.where('number in (?)', [32214422,5553221]),
than num=[32214422,5553221]; Phone.where("number in
(#{(['?']*num.size).join(',')})", *num). I'd rather write
Phone.where('(ddd,number) in (?)', [[1,2],[3,4]]) rather than a =
[[1,2],[3,4]];Phone.where("(ddd, number) in (#{(['(?, ?)']*a.size).join(',
')})", *a.flatten). Specially when Phone.where("(ddd,number) in (?)",
[[1,2],[3,4]]) generates SELECT `phones`.* FROM `phones` WHERE ((ddd,
number) in ('---\n- 1\n- 2\n','---\n- 3\n- 4\n')) which is not useful at
all.
I suggest that Phone.where("(?)", [[1,2],[3,4]]) at least throws an
exception rather than generating '(---\n- 1\n- 2\n','---\n- 3\n- 4\n)'.
Otherwise, if you're adding random characters, at least add the random
characters '(', ')' and ',' in the following maner: '(1,2),(3,4)' :P.
Unless those '---\n-' are not random.
Anyway, I believe everybody now already understands what I'm suggesting and
why. It's, of course, up to you to evaluate if any of this is an worthy
feature or not.
Cheers,
Rafael
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.