For what it's worth I was about to post a question about the same issue. In 
my case what I'm finding is basically this:

If you set up two Sequel Models, each with the json serializer plugin, then 
you do a join query, it will fail with no method error on the joined 
model's methods.

Here's my situation:
I have two models, Edition and Access. Both classes call `plugin 
:json_serializer` at the top.

If do this this:

    result = Access.join(:editions, :id => :context_id).where(:user_id => 
57)
    result.to_json

I always get NoMethodError on Edition attributes. For instance, "NoMethodError: 
undefined method `book_id' for #<Access:0x007f9c014af0c0>" (where book_id 
is actually an Edition attribute).

If I call it this way:

    result = Edition.join(:accesses, :context_id => :id).where(:user_id => 
57)
    result.to_json

I get the same NoMethodError but on Access attributes. For instance, 
"NoMethodError: 
undefined method `resource_id' for #<Edition:0x007f9c01d2f0d8>" (where 
resource_id is actually an Access attribute).

I tried including the association as well:

    result.to_json(:include => :access)

but that didn't work either.

Now, as I'm typing this up I'm thinking about something, the associations 
not declared in these classes as we're using Sequel only to read an old 
database, so not every table has a Sequel Model and not all the plumbing is 
necessary. Is that likely the issue, or is something else going on here?


On Monday, January 13, 2014 4:30:16 PM UTC-5, Jeremy Evans wrote:
>
> On Monday, January 13, 2014 1:07:20 PM UTC-8, tony wrote:
>>
>>
>> I'm aware of this already and I used it and if I do artist.to_json I get 
>> the following errors
>>
>> NoMethodError - undefined method `albums_id' for 
>> #<Artist:0x009fd541af477>:
>>
> Without a backtrace and the code you are running, I can't do much to 
> diagnose this issue.  
>
> Note that you shouldn't need to call Dataset#graph.  You should be using 
> eager_graph instead.  Perhaps something like:
>
>   Artist.eager_graph(:albums).where(:albums__sold => 
> 21).to_json(:include=>:albums)
>
> If you still need help, please submit a self-contained example showing the 
> problem.
>
> Thanks,
> Jeremy
>

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to