On Sunday, August 3, 2014 7:20:58 AM UTC-7, Adrià Planas wrote:
> Hi there, I'm not sure at all if this is a bug or it is the expected 
> behavior. I've been digging on the source code but I've been unable to find 
> why this happens.
> 
> 
> As a very simple example consider a model Comment which has a many to one 
> association :author. I'm using #eager_graph to pick the author when 
> retrieving a list of statuses and it works just fine, the problem arises when 
> I try to retrieve a computed column out of the table schema:
> 
> 
> This works fine:
> 
> Comment.select_append(Sequel.function(:to_epoch, 
> :created_at).as(:epoch_ref)).all
> 
>  I, [2014-08-03T16:11:34.822226 #42612]  INFO -- : (0.006656s) SELECT *, 
> to_epoch("created_at") AS "epoch_ref" FROM "comments"
> 
>  [#<Comment @values={:id=>147134385426653, :author_id=>3, :body=>"Hello 
> world!", :created_at=>2014-07-31 18:06:57 UTC, :updated_at=>2014-07-31 
> 18:06:57 UTC, :to_epoch=>#<BigDecimal:104b76100,'0.1406830017 
> 942663E10',27(27)>}>,...]
> 
> 
> But when used together with #eager_graph the added epoch_ref column is 
> silently ignored:
> 
>  Comment.eager_graph(:author).select_append(Sequel.function(:to_epoch, 
> :comments__created_at).as(:epoch_ref)).all
> 
> 
> [#<Comment @values={:id=>147134385426653, :author_id=>3, :body=>"Hello 
> world!", :created_at=>2014-07-31 18:06:57 UTC, :updated_at=>2014-07-31 
> 18:06:57 UTC}>...]
> 
> 
> Any thoughts?
> Thanks

This is expected, you need to use add_graph_aliases instead of select_append 
when graphing, so it knows in which object to put the resulting column.

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/d/optout.

Reply via email to