Hi there,
I''m building a private message system for one of my sites. I''m
now
trying to give users the delete messages in their inbox (not destroy
the records but put "archived = true" in them), so they don''t
come up
anymore. This is important because the sender needs to have the
message in his sent items.
Everything is set up but when I do the database query, it simply
returns no messages.
This was my query before the archive feature and shows records:
@messages = Message.find_all_by_to(current_user.id, :order =>
"created_at DESC")
And this is the query with archive feature and shows no records:
@messages = Message.find_all_by_to(current_user.id, :conditions =>
{:archived, :order => "created_at DESC")
The strange thing is that Mongrel shows the right query:
Message Load (0.6ms) SELECT * FROM "messages" WHERE
("messages"."archived" = ''false'') AND
("messages"."to" = 3) ORDER BY
created_at DESC
But I don''t see any messages anymore (archived and not archived).
Hope you can help me.
pl
Hi pl, On Mon, 2009-07-13 at 06:10 -0700, pl wrote:> The strange thing is that Mongrel shows the right query: > Message Load (0.6ms) SELECT * FROM "messages" WHERE > ("messages"."archived" = ''false'') AND ("messages"."to" = 3) ORDER BY > created_at DESC > > But I don''t see any messages anymore (archived and not archived).What does the database return if you execute the select outside of your app? (I''m assuming you either know the command-line syntax or have a GUI front-end.) Bill
The problem is in the query:
sqlite> SELECT * FROM "messages" WHERE
("messages"."to" = 3) ORDER BY
created_at DESC;
23|Hoi Pepijn|7|3|true|2009-07-13 07:40:41|2009-07-13 13:13:45|t
22|Hoi testje|7|3|true|2009-07-13 07:21:44|2009-07-13 07:33:48|f
21|Hoi sjaak|7|3|true|2009-07-13 07:12:19|2009-07-13 07:36:59|f
19|En nu dan?|7|3|true|2009-07-13 07:02:20|2009-07-13 07:34:59|f
17|Heel misschien nu|7|3|true|2009-07-13 06:46:40|2009-07-13 07:35:09|
f
15|Hoi Pepi!|7|3|true|2009-07-13 06:40:30|2009-07-13 07:35:35|f
sqlite> SELECT * FROM "messages" WHERE
("messages"."archived" ''false'') AND
("messages"."to" = 3) ORDER BY created_at DESC;
sqlite>
Suggestions for a better query? Is it an SQLite/MySQL difference?
Never used SQLite before.
On 13 jul, 15:23, bill walton
<bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hi pl,
>
> On Mon, 2009-07-13 at 06:10 -0700, pl wrote:
> > The strange thing is that Mongrel shows the right query:
> > Message Load (0.6ms) SELECT * FROM "messages" WHERE
> > ("messages"."archived" =
''false'') AND ("messages"."to" = 3) ORDER
BY
> > created_at DESC
>
> > But I don''t see any messages anymore (archived and not
archived).
>
> What does the database return if you execute the select outside of your
> app? (I''m assuming you either know the command-line syntax or
have a
> GUI front-end.)
>
> Bill
On Mon, 2009-07-13 at 06:46 -0700, pl wrote:> The problem is in the query: > > sqlite> SELECT * FROM "messages" WHERE ("messages"."to" = 3) ORDER BY > created_at DESC; > 23|Hoi Pepijn|7|3|true|2009-07-13 07:40:41|2009-07-13 13:13:45|t > 22|Hoi testje|7|3|true|2009-07-13 07:21:44|2009-07-13 07:33:48|f > 21|Hoi sjaak|7|3|true|2009-07-13 07:12:19|2009-07-13 07:36:59|f > 19|En nu dan?|7|3|true|2009-07-13 07:02:20|2009-07-13 07:34:59|f > 17|Heel misschien nu|7|3|true|2009-07-13 06:46:40|2009-07-13 07:35:09| > f > 15|Hoi Pepi!|7|3|true|2009-07-13 06:40:30|2009-07-13 07:35:35|f > sqlite> SELECT * FROM "messages" WHERE ("messages"."archived" > ''false'') AND ("messages"."to" = 3) ORDER BY created_at DESC; > sqlite> > > Suggestions for a better query? Is it an SQLite/MySQL difference? > Never used SQLite before.If I''m reading the results above correctly, it looks like the ''archived'' field is the one at the end. Yes? If so, then the query needs to test for ''f'' not ''false''. If not, this it looks like the archived field must be the one just before the first date and you show no records with a value of ''false''. HTH, Bill> On 13 jul, 15:23, bill walton <bwalton...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi pl, > > > > On Mon, 2009-07-13 at 06:10 -0700, pl wrote: > > > The strange thing is that Mongrel shows the right query: > > > Message Load (0.6ms) SELECT * FROM "messages" WHERE > > > ("messages"."archived" = ''false'') AND ("messages"."to" = 3) ORDER BY > > > created_at DESC > > > > > But I don''t see any messages anymore (archived and not archived). > > > > What does the database return if you execute the select outside of your > > app? (I''m assuming you either know the command-line syntax or have a > > GUI front-end.) > > > > Bill > >