Ha! Okay. The conventions of Sequel are still tripping me up a bit.
".all" is the solution here. I looked for my first problem, but
searching this list for that MySQL error gave me the answer.

On Feb 14, 5:47 pm, cult hero <[email protected]> wrote:
> Perhaps I'm miss understanding something but, it seems that if I
> combine a filter and associations, I run into a world problems.
>
> I have what I think is a pretty simple association in a model:
>
> -----
> class AssetEvent < Sequel::Model
>
>   set_dataset dataset.order(:date_start, :date_circa.desc)
>   many_to_one :base, :class => Asset, :key
> => :asset_id, :graph_join_type => :inner
>
>   def year()
>     self.date_start.year
>   end
>
>   ... (omitted)
> end
> -----
>
> (date_start is just a Date field in MySQL)
>
> Example 1: Eager loading the association.
>
> @events = AssetEvent.filter(:date_start >= DateTime.new
> (start_year)).filter(:date_start < DateTime.new(end_year)).eager_graph
> (:base)
>
> This loads everything all right, but if I iterate though events
> using .each I get this error when I try to call my year method:
>
> undefined method `year' for #<Hash:0x19f602c>
>
> So... it's returning a hash instead of a normal dataset?
>
> Example 2: Fine, I won't do an eager load and see if that solves it.
>
> @events = AssetEvent.filter(:date_start >= DateTime.new
> (start_year)).filter(:date_start < DateTime.new(end_year))
>
> So I iterate using .each and...
>
> Mysql::Error Commands out of sync; you can't run this command now
>
> What really confuses me is that both of these work just fine if I
> don't use .filter and just grab the whole table. I've checked to make
> sure the SQL produced by the filter statements is good, and it is so
> I'm totally confused. Does filtering a model kill all its methods or
> what?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to