you can either make a non-primary mapper() for the class with 
“include_attributes” and set that as the target of the relationship, or you can 
use the new load_only() loader option at query time.

On Nov 18, 2013, at 3:27 PM, Jonathan Vanasco <[email protected]> wrote:

> this is just wild thinking -- and might not be possible.
> 
> 
> I'm  wondering if anyone has some ideas on creating a relationship where only 
> certain columns are queried during relationship loading.
> 
> I have a few relationships like this ( pseudocode )
> 
>     class Tag2Posting:
>         tag_id INT
>         posting_id INT
> 
>          tag = sa.relationship( Tag )
>          posting = sa.relationship( Posting )
> 
> 
>     class Tag:
>          id  
>          name 
>          to_postings = sa.relationship( Tag2Posting )
> 
> 
>     class Posting:
>          id INT
>          to_tags = sa.relationship( Tag2Posting )
> 
> 
> accessing the relationship will pull the entire object.
> 
>       posting_a.to_tags -->generates--> "SELECT tag_id , posting_id FROM 
> tag_2_posting"
> 
> 
> I really only care about the "tag_id" , so I'd want to create a relationship 
> that generates this sql :
> 
>       "SELECT tag_id FROM tag_2_posting"
> 
> that would probably create either an array of ids:
> 
>         posting_a.tag_ids = [1,2,3]
> 
> 
> a similar , but different, concept would be an object where certain columns 
> are Deferred when loaded through a relationship ( and normal otherwise ). 
> 
> 
> this is a bad example, because i'm using a 2 column association object.  but 
> it makes a lot of sense when there's no association object and you end up 
> querying a ton of data that will not be used.
> 
> 
> -- 
> 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 [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/groups/opt_out.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to