Sorry, I suppose by “wrong” I meant “incomplete”.

There is a `binds` argument, and it seems to be used, but it is not
documented.

On Thu, Jun 25, 2015 at 11:54 AM, James Coleman <[email protected]> wrote:

> @TJ: No, I don't believe the docs are wrong. If you try the examples they
> only work as documented, and fail if go by what you'd expect from the
> method definition instead.
>
> On Thu, Jun 25, 2015 at 11:48 AM, T.J. Schuck <[email protected]> wrote:
>
>> The `bind` argument was added as `bind_values` all the way back in 2010,
>> with no change to the documentation:
>> https://github.com/rails/rails/commit/cc468d3ec81d6f1298fca91c0549584b36dafcc6
>>
>> So the docs are probably just wrong — I’m sure a documentation PR would
>> be quickly merged.
>>
>> On Thu, Jun 25, 2015 at 11:18 AM, James Coleman <[email protected]> wrote:
>>
>>> Furthermore, the definition of find_by_sql truly is confusing in because
>>> when used the way the docs say to call it, the binds variable does not
>>> contain the bind variable. For example:
>>>
>>> irb(main):010:0> def t(x, y=[])
>>> irb(main):011:1> puts "x: #{x.inspect}"
>>> irb(main):012:1> puts "y: #{y.inspect}"
>>> irb(main):013:1> end
>>> => :t
>>> irb(main):014:0> t(1,2)
>>> x: 1
>>> y: 2
>>> => nil
>>> irb(main):016:0> t([1,2])
>>> x: [1, 2]
>>> y: []
>>>
>>> On Thu, Jun 25, 2015 at 11:06 AM, Nicolás Sanguinetti <[email protected]
>>> > wrote:
>>>
>>>> > You need to have a deeper understanding of ruby, and specifically the
>>>> magic of the splat (*) operator.
>>>>
>>>> I think you missed that the method signature is `def find_by_sql(sql,
>>>> binds = [])`, and not `def find_by_sql(sql, *binds)`. There’s no splat in
>>>> the method signature.
>>>>
>>>> Before trying to belittle someone, maybe make sure that you’re actually
>>>> correct :P
>>>>
>>>>  Remember MINSWAN, people.
>>>>
>>>> (As for the on-topic conversation, sorry, I have no idea what’s going
>>>> on with that `binds` argument.)
>>>>
>>>> Cheers,
>>>> -foca
>>>>
>>>>
>>>>
>>>>
>>>> On Thu, Jun 25, 2015 at 2:38 PM, Matias Korhonen <
>>>> [email protected]> wrote:
>>>>
>>>>> Hi,
>>>>>
>>>>>
>>>>> We happened to need #find_by_sql today and noticed that it appears to
>>>>> have a somewhat confusing interface/method definition/documentation.
>>>>>
>>>>> The method definition is:
>>>>>
>>>>>  def find_by_sql(sql, binds = [])
>>>>>>   # ...
>>>>>> end
>>>>>
>>>>>
>>>>> Which would seem to imply that you should use it like this:
>>>>>
>>>>>  Post.find_by_sql("SELECT * FROM posts WHERE id = ?", [1])
>>>>>
>>>>>
>>>>> However, that is wrong, you actually need to do (and the examples in
>>>>> the documentation are like this):
>>>>>
>>>>>  Post.find_by_sql(["SELECT * FROM posts WHERE id = ?", 1])
>>>>>
>>>>>
>>>>> I spent some time reading the documentation and code and can't figure
>>>>> out what the binds argument should be used for.
>>>>>
>>>>> Maybe some sort of example or explanation should be added to the
>>>>> #find_by_sql documentation? I'd do so myself, but I'm having trouble
>>>>> figuring it out…
>>>>>
>>>>>
>>>>> — Matias
>>>>>
>>>>>  --
>>>>> 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.
>>>>> 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 [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at http://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 [email protected].
>>> To post to this group, send email to [email protected].
>>> Visit this group at http://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 [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at http://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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to