Find by boolean

1 view
Skip to first unread message

joshmckin

unread,
Sep 30, 2010, 7:05:33 PM9/30/10
to SimpleRecord
I would like to use find_by to query a model with a boolean value, but
get Aws::AwsError: InvalidQueryExpression: The specified query
expression syntax is not valid.


For example:

class Pages < SimpleRecord::Base
has_booleans :disabled
end

Pages.find_all_by_disabled(false)


I guessing this is probably not going to possible since the boolean is
saved a string in simpledb and the find_by methods would not be smart
enough to look for all the string forms of boolean values in the
simpledb that simple record would use (like "true", "1", "0", "false",
nil/null...).

Am I correct?

Travis Reeder

unread,
Oct 1, 2010, 3:46:41 PM10/1/10
to simple...@googlegroups.com
Hmmm, it should work I would think. Can you send in the select expression it's sending in, should show up with that AwsError.


--
You received this message because you are subscribed to the Google Groups "SimpleRecord" group.
To post to this group, send email to simple...@googlegroups.com.
To unsubscribe from this group, send email to simple-recor...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/simple-record?hl=en.


joshmckin

unread,
Oct 1, 2010, 5:13:33 PM10/1/10
to SimpleRecord
Page.find_by_disabled(false)
produces
##### Aws::SdbInterface request: sdb.amazonaws.com:443/?
AWSAccessKeyId=SOMEKEYID&Action=Select&SelectExpression=SELECT%20%2A
%20FROM%20%60pages%60%20WHERE%20disabled%3D%20LIMIT
%201&SignatureMethod=HmacSHA256&SignatureVersion=2&Timestamp=2010-10-01T20%3A00%3A56.000Z&Version=2009-04-15&Signature=SOMESIGNATURE
####


From the looks of it, the query is not converting the boolean false to
a string "false". Boolean true does not produce the query error but
only find attributes with the string "true", attributes with "1" are
ignored.

I begun homogenizing my booleans with a before save that converts all
boolean values with the literal string representation ie true =>
"true", false => "false", which solves the "1", "0" problem for me but
some folks may prefer "0", "1"

Not sure its possible but it would be nice if the finds would identify
attributes as boolean and expand the query string to include all
"reasonable" string boolean representations, but this too seems like
I'm asking a lot of simple_record

Just an idea.

On Oct 1, 2:46 pm, Travis Reeder <tree...@gmail.com> wrote:
> Hmmm, it should work I would think. Can you send in the select expression
> it's sending in, should show up with that AwsError.
>
> On Thu, Sep 30, 2010 at 4:05 PM, joshmckin <joshmc...@gmail.com> wrote:
> > I would like to use find_by to query a model with a boolean value, but
> > get Aws::AwsError: InvalidQueryExpression: The specified query
> > expression syntax is not valid.
>
> > For example:
>
> > class Pages < SimpleRecord::Base
> >  has_booleans :disabled
> > end
>
> > Pages.find_all_by_disabled(false)
>
> > I guessing this is probably not going to possible since the boolean is
> > saved a string in simpledb and the find_by methods would not be smart
> > enough to look for all the string forms of boolean values in the
> > simpledb that simple record would use (like "true", "1", "0", "false",
> > nil/null...).
>
> > Am I correct?
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "SimpleRecord" group.
> > To post to this group, send email to simple...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > simple-recor...@googlegroups.com<simple-record%2Bunsu...@googlegroups.com>
> > .

Travis Reeder

unread,
Oct 15, 2010, 12:15:47 AM10/15/10
to simple...@googlegroups.com
SimpleRecord stores booleans as "true"/"false".

Looks like it's not adding the boolean to the query for some reason: 
SELECT * FROM `pages` WHERE disabled= LIMIT 1

I'm sure it's a quick fix, feel free to have a stab at it if you'd like. 

To unsubscribe from this group, send email to simple-recor...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages