http://wikipedlla.com/problem_with_mysql_adapter_and_models
I have a sample app I'm building with a simple entry table:
create_table :entries do
nbsp; primary_key :id
nbsp; text :name
nbsp; text :title
nbsp; text :summary
nbsp; text :content
end
and another comment table:
Blog::Models::Entry.all.first.comments.sort_by(:created_on)
How are these different? Should the first variant work because of the
call to #all?
.comments returns a dataset here, not an actual array, so you can't
sort_by() on it. Using ruby's sort_by is going to be slower anyway, so
its
e = Entry.all.first
# same as
# e = Entry.first
Actually, these aren't really the same. The first will fetch all
entries in the table into a ruby array, then pick the first one from
the array. The second will run a LIMIT 1 query and only fetch the
first entry from the table, making it
First, thank you for the suggestions as to how to better use the
Sequel API: they are very helpful.
Second, I still have a question. :)
Blog::Models::Entry.all.first.comments.sort_by(:created_on)
[ ... snip ... ]
The workaround is to use .all, so that the results from the initial
query
As you would expect, I can do something like:
Blog::Models::Entry.all.first.comments
.all returns an array of model instances.. so you're actually fetching
all your blog entries into a ruby array and then picking the first
one. If, instead, you do:
Entry.first.comments
it will only get
Dan,
Several people have been seeing this issue.
Thank you for looking further into this.
~Wayne
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
sequel-talk group.
To post to this group, send email to