Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
ActiveRecord conditions: Symbol or String
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
dnagir  
View profile  
 More options Apr 19 2012, 11:15 pm
From: dnagir <dna...@gmail.com>
Date: Thu, 19 Apr 2012 20:15:50 -0700 (PDT)
Local: Thurs, Apr 19 2012 11:15 pm
Subject: ActiveRecord conditions: Symbol or String

Hi,

A quick question: in the query `Company.where(:status => :active)`, is it
OK to use the symbol (:active) as a value in the query?

It definitely works with no issues at all.

But there's a lot of controversy around that in the squeel:
https://github.com/ernie/squeel/issues/67#issuecomment-5237083

Ernie explains that the use of Symbols in ActiveRecord wasn't assumed and
is incorrect.
Additionally, he says "In AR documentation, symbols are never shown as a
value in examples.".

I personally feel a bit lost in this regard and it would be awesome if
somebody could shade some light on this.

Cheers,
Dmytrii.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Koziarski  
View profile  
 More options Apr 20 2012, 12:13 am
From: Michael Koziarski <mich...@koziarski.com>
Date: Fri, 20 Apr 2012 16:13:42 +1200
Local: Fri, Apr 20 2012 12:13 am
Subject: Re: [Rails-core] ActiveRecord conditions: Symbol or String

> Hi,

> A quick question: in the query `Company.where(:status => :active)`, is it OK to use the symbol (:active) as a value in the query?

> It definitely works with no issues at all.

I'm not sure I'd consider it a public stable API, but if it works, go wild :).

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmytrii Nagirniak  
View profile  
 More options Apr 20 2012, 6:21 am
From: Dmytrii Nagirniak <dna...@gmail.com>
Date: Fri, 20 Apr 2012 20:21:44 +1000
Local: Fri, Apr 20 2012 6:21 am
Subject: Re: [Rails-core] ActiveRecord conditions: Symbol or String

On 20/04/2012, at 2:13 PM, Michael Koziarski wrote:

>> Hi,

>> A quick question: in the query `Company.where(:status => :active)`, is it OK to use the symbol (:active) as a value in the query?

>> It definitely works with no issues at all.

> I'm not sure I'd consider it a public stable API, but if it works, go wild :).

So it is not a public API and the symbols were not supposed to be used this way? RIght?

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jon Leighton  
View profile  
 More options Apr 20 2012, 7:30 am
From: Jon Leighton <j...@jonathanleighton.com>
Date: Fri, 20 Apr 2012 13:30:16 +0200
Local: Fri, Apr 20 2012 7:30 am
Subject: Re: [Rails-core] ActiveRecord conditions: Symbol or String
On 20/04/12 12:21, Dmytrii Nagirniak wrote:

>>> Hi,

>>> A quick question: in the query `Company.where(:status =>  :active)`, is it OK to use the symbol (:active) as a value in the query?

>>> It definitely works with no issues at all.

>> I'm not sure I'd consider it a public stable API, but if it works, go wild :).

> So it is not a public API and the symbols were not supposed to be used this way? RIght?

It's not really good Ruby style. See
http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings

However I think we'd probably have to add specific code to make it *not*
work, so it will probably continue to work in the future. But I wouldn't
recommend doing it.

--
http://jonathanleighton.com/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmytrii Nagirniak  
View profile  
 More options Apr 22 2012, 10:37 pm
From: Dmytrii Nagirniak <dna...@gmail.com>
Date: Mon, 23 Apr 2012 12:37:00 +1000
Subject: Re: [Rails-core] ActiveRecord conditions: Symbol or String

On 20/04/2012, at 9:30 PM, Jon Leighton wrote:

> On 20/04/12 12:21, Dmytrii Nagirniak wrote:
>>>> Hi,

>>>> A quick question: in the query `Company.where(:status =>  :active)`, is it OK to use the symbol (:active) as a value in the query?

>>>> It definitely works with no issues at all.

>>> I'm not sure I'd consider it a public stable API, but if it works, go wild :).

>> So it is not a public API and the symbols were not supposed to be used this way? RIght?

> It's not really good Ruby style. See http://blog.hasmanythrough.com/2008/4/19/symbols-are-not-pretty-strings

Do you mind to explain why exactly?
I get the difference between strings and symbols, but in the example of "status" the string is definitely a wrong candidate to me.
It is "internal" to the system.
Although I understand and ok with converting it to a string to query, I don't see why symbol isn't good in this case (`company.status == :active`).

> However I think we'd probably have to add specific code to make it *not* work, so it will probably continue to work in the future. But I wouldn't recommend doing it.

I think you guys have settled that symbols are not "officially supported" here https://github.com/ernie/squeel/issues/67#issuecomment-5270896

So I'll take it for granted. Thanks a lot for the help.

Cheers.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dmytrii Nagirniak  
View profile  
 More options Apr 22 2012, 11:50 pm
From: Dmytrii Nagirniak <dna...@gmail.com>
Date: Mon, 23 Apr 2012 13:50:45 +1000
Local: Sun, Apr 22 2012 11:50 pm
Subject: Re: [Rails-core] ActiveRecord conditions: Symbol or String

On 23/04/2012, at 12:37 PM, Dmytrii Nagirniak wrote:

> I think you guys have settled that symbols are not "officially supported" here https://github.com/ernie/squeel/issues/67#issuecomment-5270896

> So I'll take it for granted. Thanks a lot for the help.

Thus, this docrails commit. Hope that makes any sense.
https://github.com/lifo/docrails/commit/50c5005bafe7e43f81a141cd2c512...

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »