Ok I think I finally understand, maybe.
Single value tuple wheres are/were supported:
http://stackoverflow.com/questions/15750234/ruby-activerecord-and-sql-tuple-support
e.g. Person.where("(name, address) IN ((?))", ['John', '123 Main St'])
And you are right that one would expect that if that is supported then
because of:
http://guides.rubyonrails.org/active_record_querying.html#subset-conditions
Client.where(:orders_count => [1,3,5]) # => "SELECT * FROM clients WHERE
(clients.orders_count IN (1,3,5))"
That you would expect this to work:
Person.where("(name, address) IN ((?))", [['John', '123 Main St'],['Mary',
'321 Easy St']])
But, a where value that is an array could also be an array type in the
database, per Jeremy adding multiline string support.
So I think the question is really about "where" being a little too
ambiguous about the intent.
If tuples are already supported in AR (which it looks like they are), then
even there is not first-class tuple support in every database, I'm actually
leaning towards maybe a where_tuple or similar method being a better way
for ActiveRecord to continue formally supporting tuples in a more intuitive
way, so that:
Person.where_tuple([:name, :address] => [['John', '123 Main St'],['Mary',
'321 Easy St']])
and:
Person.where_tuple("(name, address) IN ((?))", [['John', '123 Main
St'],['Mary', '321 Easy St']])
would work. But for the short-term, I think doing that in a gem or as a
patch in an initializer might be the best solution.
On Thursday, May 23, 2013 3:54:39 AM UTC-4, Rafael Almeida wrote:
>
> 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.