What's wrong with this find statement?

2 views
Skip to first unread message

Carson

unread,
Apr 23, 2008, 12:32:27 PM4/23/08
to Beginning Ruby on Rails E-Commerce
@products = Product.find(:all, :conditions => "on_catalog_promotion =
true" )

produces this error message:

SQLite3::SQLException: no such column: true: SELECT * FROM products
WHERE (on_catalog_promotion = true)

The Products table has such a column and it is filled with true or
false for each product.

Any ideas? I'm puzzled.

Carson

Jarkko Laine

unread,
Apr 23, 2008, 1:36:49 PM4/23/08
to railsec...@googlegroups.com

On 23.4.2008, at 19.32, Carson <E.Carson...@gmail.com> wrote:

>
> @products = Product.find(:all, :conditions => "on_catalog_promotion =
> true" )
>

Try these:

:conditions => {:on_catalog_promotion => true}

Or

:conditions => "on_catalog_promotion is true"

//jarkko

Ed Campbell

unread,
Apr 23, 2008, 4:12:53 PM4/23/08
to railsec...@googlegroups.com
Well, appearantly, the :conditions option only accepts boolean comparison to "1" or "0" -- not "true" or "false". I changed and reloaded the fixture and it worked fine.
 
Thanks, sometimes the answer only comes to me after I've asked for help.
 
Carson

Jarkko Laine

unread,
Apr 23, 2008, 5:19:02 PM4/23/08
to railsec...@googlegroups.com

On 23.4.2008, at 23.12, Ed Campbell wrote:

> Well, appearantly, the :conditions option only accepts boolean
> comparison to "1" or "0" -- not "true" or "false". I changed and
> reloaded the fixture and it worked fine.
>
> Thanks, sometimes the answer only comes to me after I've asked for
> help.

:conditions the way you used it just passes the string straight to SQL
so it's a matter of whether the SQL engine you use accepts it. In that
sense it's always safer to use the hash form when your conditions are
simple enough for it, or the array form:

:conditions => ["on_catalog_promotion = ?", true]

Using those, the db adapter will take care of using correct options in
the SQL statement. In your case, I would prefer the hash form because
it looks the cleanest and doesn't require any use of strings. Note
that this is also exactly the same as
Product.find_all_by_on_catalog_promotion(true), which might win the
beauty contest in someone's book.

//jarkko

>
> Carson
>
> On Wed, Apr 23, 2008 at 12:36 PM, Jarkko Laine <jar...@jlaine.net>
> wrote:
>
>
>
> On 23.4.2008, at 19.32, Carson <E.Carson...@gmail.com> wrote:
>
> >
> > @products = Product.find(:all, :conditions =>
> "on_catalog_promotion =
> > true" )
> >
>
> Try these:
>
> :conditions => {:on_catalog_promotion => true}
>
> Or
>
> :conditions => "on_catalog_promotion is true"
>
> //jarkko
>
> > produces this error message:
> >
> > SQLite3::SQLException: no such column: true: SELECT * FROM products
> > WHERE (on_catalog_promotion = true)
> >
> > The Products table has such a column and it is filled with true or
> > false for each product.
> >
> > Any ideas? I'm puzzled.
> >
> > Carson
> > >
>
>
>
>

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "Beginning Ruby on Rails E-Commerce" group.
> To post to this group, send email to railsec...@googlegroups.com
> To unsubscribe from this group, send email to railsecommerc...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/railsecommerce?hl=en
> -~----------~----~----~----~------~----~------~--~---
>

--
Jarkko Laine
http://jlaine.net
http://dotherightthing.com
http://www.railsecommerce.com
http://odesign.fi


Ed Campbell

unread,
Apr 24, 2008, 11:48:48 AM4/24/08
to railsec...@googlegroups.com
Well, Jarkko, I always learn something when I receive a reply from you. Thanks.
 
I have a nagging question from when I worked through your e-comm project a couple of months ago. Your db:migration for Carts has no fields listed (one is there, but it is commented out). That means that it only records a system generated id, correct? Is that its only purpose?
 
Regards,
 
Carson

Jarkko Laine

unread,
Apr 25, 2008, 4:19:12 AM4/25/08
to railsec...@googlegroups.com

On 24.4.2008, at 18.48, Ed Campbell wrote:

> Well, Jarkko, I always learn something when I receive a reply from
> you. Thanks.
>
> I have a nagging question from when I worked through your e-comm
> project a couple of months ago. Your db:migration for Carts has no
> fields listed (one is there, but it is commented out). That means
> that it only records a system generated id, correct? Is that its
> only purpose?

In that phase of the system, yes, since there's no user authentication
or anything for customers.

//jarkko

> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google
> Groups "Beginning Ruby on Rails E-Commerce" group.
> To post to this group, send email to railsec...@googlegroups.com
> To unsubscribe from this group, send email to railsecommerc...@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/railsecommerce?hl=en
> -~----------~----~----~----~------~----~------~--~---
>

--

Reply all
Reply to author
Forward
0 new messages