On Aug 22, 2007, at 2:31 PM, Christoph Haas wrote:

> The error disappeared. But getting the joined PTR records for a  
> certain
> inet took very long. So I analyzed the query that SQLAlchemy did:
>
>     SELECT records.id AS records_id, records.domain_id AS
>     records_domain_id, records.dhcpzone_id AS records_dhcpzone_id,
>     records.name AS records_name, records.type AS records_type,
>     records.content AS records_content, records.ttl AS records_ttl,
>     records.prio AS records_prio, records.change_date AS
>     records_change_date, records.mac_address AS records_mac_address,
>     records.inet AS records_inet
>     FROM records, records AS records_1
>     WHERE records_1.type = %(records_1_type)s AND %(param_2)s =
>     records_1.inet ORDER BY records.id
>
>     {'records_1_type': 'PTR', 'param_2': '10.20.30.40'}
>
> The "FROM records, records AS records_1" looks suspiciously like a
> cartesian product. And I get all possible results - not just rows with
> type=='PTR'. The "childs" from records_1 have the right criteria. But
> I get all "records". :(

OK, it seems like its using the primary mapper for the lazy load and  
not the secondary mapper you created.   I think at this point I'd  
have to dig in and see whats up, except im going out of town  
tomorrow.  So you should add a trac ticket with an example script  
that one of us can look at.

>
> I'm not sure if JOIN is the right paradigm here. Usually I'd use a
> SELECT. But "select" in SQLAlchemy's world doesn't seem to return  
> mapped
> objects but rather plain rows. I assume it's not supported to add a
> "filter()" statement as a property?

its supported.  you can use a dynamic_loader() relation, which  
basically attaches a Query as the collection used by the relation().   
However, the self-referential-non-adjacency list thing happening here  
might get in the way again.

>
> Perhaps you have another hint. Would be a pity to give up and use my
> dirty @property method. Thanks so far.

the @property youre using *is* the most straightforward way to do  
this.  if caching is the only issue, just have your @property store  
the result in a list and return that.  there isnt really a "relation"  
happening here, no foreign key or anything, so to some degree you're  
repurposing what "relation()" is meant to do (but is still very  
common..everyone wants relation() to wash their dishes and take out  
their trash.... :)  )



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" 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/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to