Here was my response to Nels:

On Mon, Dec 2, 2013 at 9:00 PM, Nels Nelson <[email protected]> wrote:

>
>
> On Monday, December 2, 2013 9:33:03 PM UTC-6, Jeremy Evans wrote:
>>
>> You could try switching to an after_load hook on the association instead 
>> of after_initialize hook on the model.
>>
>
> Thank you!  I completely failed to find that in the docs.  I'm sure it's 
> there, and I just missed it.  It is exactly ideal, and it works perfectly.
>

Great!
 

> Unfortunately, I cannot seem to reliably get rcte tree model instances to 
>>> keep themselves in a global in-memory cache (let alone a memcached 
>>> instance), and from it be subsequently retrieved.  It seems that only some 
>>> instances are loaded into the cache, and then only the main model instance, 
>>> with none of its associations.
>>>
>>
>> Well, for the children association, this is expected, since Sequel 
>> doesn't support a cache lookup for one_to_many associations.  For the 
>> parent association, it should use a cache lookup if you are using the 
>> caching plugin.
>>
>
> Interesting, I did not know this.  However, what I meant was, that only 
> the main model instance seems to get loaded into cache, and none of its 
> non-rcte tree associations -- that is, ideally I would prefer that the 
> non-child many-to-many associations get automatically loaded along with the 
> model instance.
>

I'm not exactly sure what you are describing (example code would help).  Is 
it that the model instance is cached without any associations, or cached 
with some associations and not others (even though those associations were 
present in @associations at time of caching), or that in the uncached case 
@associations is not prepopulated with some associations that you want to 
be prepopulated.
 

>
> use Dataset#eager on the dataset that creates the objects, or the 
>> tactical_eager_loading plugin, in conjuction with Dataset#all to load the 
>> objects.
>>
>
> Is it possible to do this automatically? [*] That is, upon retrieving the 
> children of a node, and dealing with an individual instance within that 
> set, is it possible to specify that all of that node instance's normal 
> many-to-many association members (non-rcte tree associations) get 
> implicitly included in the query which fetches those children?
>

Again, I'm not exactly sure what you are asking for here.  If you want to 
eagerly load associations for associated objects, you can use the :eager 
option.  Note that like usual eager loading, this is an additional query. 
 Something like this after loading the rcte_tree plugin may help:

one_to_many :children, :clone=>:children, :eager=>:other_assoc
 
Note that if you use the tactical_eager_loading plugin, you shouldn't need 
to do this, as it will eager load implicitly in most cases.  In either the 
:eager or tactical_eager_loading case, obj.children.each{|c| c.other_assoc} 
should be only 2 queries regardless of the number of children).

The query you post does not make sense in rcte_tree context, since it 
>> appears to be using a join table, and the rcte_tree plugin does not.
>>
>
> Yes.  So, Artists could be considered to be nodes in the tree, and albums 
> are normal non-hierarchical many-to-many associations, joined through an 
> artist_to_album table and entity.
>

That makes sense.
 

> I think that I understand that this may not be possible in conjunction 
>>> with the rcte_tree plugin for Sequel.  For some reason I was under the 
>>> impression that association eager loading was working for normal 
>>> associations, just not for the tree associations.  (Perhaps until recently?)
>>>
>>
>> The only thing the rcte_tree plugin gives you is that it allows you do 
>> get all ancestors or descendents (or descendents to some level) in a single 
>> query.  You so far have not described usage of those features, so you are 
>> probably just using the associations added by the tree plugin (which the 
>> rcte_tree plugin loads).
>>
>
> I do use ancestors and descendants elsewhere in the program, but there is 
> one spot in the program where a given node's branch is programmatically 
> pre-order traversed, and information retrieved.  I may have to rework this, 
> because it is bit of a performance pain point for the application.
>

That sounds interesting.  If you want to provide details, I may be able to 
give advice in that area. 
 

> However, the associations with which I am concerned are not the children 
> associations.  They are just the normal many-to-many associations on the 
> individual nodes.
>

OK.  I think the standard association :eager option or the 
tactical_eager_loading plugin should help in those cases, modulo caching 
issues.
 
BTW, I'm not sure if you wanted to reply directly to me or to sequel-talk. 
 I usually prefer conversations be public on sequel-talk so other users can 
benefit, but if there's a reason you want to keep the conversation private, 
that's fine with me.

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