On Wednesday, March 30, 2016 at 12:46:01 AM UTC-4, Mike Bayer wrote:

why can't you build a relationship() which has its primaryjoin set up to 
> do this?  You can do it w/ a correlated subquery. 
>

Can you reference an example ?
 

> That is, unless you want this relationship() to load differently up 
> front with options.  if you just want the limit() to change, put a 
> bindparam() inside of limit() and then use this approach: 
>

I should have stated my goals differently:

on ItemView, I need to load & iterate the last 5 items on the relationship
on OtherViews, I will eventually need to note `contains_eager`.

I just used the dynamic relationship for now, along with a property that 
loads/caches the last 5.  this allows me to hit the relationship multiple 
times with only one load.  (see below)

the actual context, btw, is a tool for managing LetsEncrypt certificate 
deployments.  

---

    certificate_requests = 
sa.orm.relationship("LetsencryptCertificateRequest",
                                              
 
primaryjoin="LetsencryptAccountKey.id==LetsencryptCertificateRequest.letsencrypt_account_key_id",
                                              
 back_populates='letsencrypt_account_key',
                                              
 order_by='LetsencryptCertificateRequest.id.desc()',
                                               lazy="dynamic",
                                               )

    @property
    def certificate_requests_5(self):
        if self._certificate_requests_5 is None:
            self._certificate_requests_5 = self.certificate_requests\
                
.options(sa.orm.joinedload('certificate_request_to_domains').joinedload('domain'),
                         )\
                .limit(5)\
                .all()
        return self._certificate_requests_5
    _certificate_requests_5 = None






 

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to