Mapper on several columns only (multiple column_property)

8 views
Skip to first unread message

naktinis

unread,
Nov 27, 2009, 8:00:39 AM11/27/09
to sqlalchemy
What is the best way to map several columns from one table to another
table? Let's say I have two classes: LargeComplicatedClass and
AnotherClass.

LargeComplicatedClass which is has a lot of eager loads and columns
with a lot of data, which is expensive to query.

I also have a AnotherClass to which I want to map
LargeComplicatedClass.title columns, so it would be many-to-many
relationship. If I would setup a usual mapper it would look something
like:

mapper(AnotherClass, another_class_table, properties={
'related_large_objects': relation(LargeComplicatedClass,
secondary=...)
})

But that would load the whole LargeComplicatedClass (I can't turn off
eager load for that class, because usually I have to use all its
fields, except for rare cases like this one).

What I need is something like this:

mapper(AnotherClass, another_class_table, properties={
'related_large_titles': customwhateverrelation
([large_complicated_table.c.title], secondary=...)
})

It is similar to column_property, except that this would be a many-to-
many relation.

Does that make sense? Or maybe I've missed some point?

Michael Bayer

unread,
Nov 27, 2009, 2:15:31 PM11/27/09
to sqlal...@googlegroups.com
you can build a second mapper for LargeComplicatedClass that doesn't have
all the eager loads - you can pass the Mapper object as the target for
relation(). The LCC instances themselves will maintain the behavior
assigned to them by their primary mapper.

>
> --
>
> You received this message because you are subscribed to the Google Groups
> "sqlalchemy" group.
> To post to this group, send email to sqlal...@googlegroups.com.
> To unsubscribe from this group, send email to
> sqlalchemy+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/sqlalchemy?hl=en.
>
>
>

Reply all
Reply to author
Forward
0 new messages