Simplifying the model with assign_mapper

Thanks to all comments to my previous post, I managed to further simplify the model.


  • I don’t have to define any variables for the model classes.
  • The session and metadata are imported from TurboGears.

Same functionality as before, but shorter ( at the bottom of the post).

A developer who doesn’t write unit tests will for sure write a bunch of hard to find bugs with a dynamically typed language like Python (like setting a wrong variable before an update: project.ttle=title). But hey, If it’s not tested, it’s broken.

Bruce Eckel has a good article for Java developers about weak typing: Strong Typing vs. Strong Testing (compare to previous SQLAlchemy version ):

from sqlalchemy import *
from sqlalchemy.ext.assignmapper import assign_mapper
import turbogears
from turbogears.database import metadata, session
#same table definitions as before
class Project(object):
class Action(object):
class Tag(object):
class Context(object):

assign_mapper(session.context,Tag, tags)
actionmapper = assign_mapper(session.context,Action, actions, properties = {
    'tags' : relation(Tag, secondary=tagaction)
projectmapper = assign_mapper(session.context,Project, projects, properties={
    'actions' : relation(Action, backref='project', order_by=actions.c.priority),
contextmapper = assign_mapper(session.context,Context, contexts, properties={
    'actions' : relation(Action, backref='context'),

18 Responses to Simplifying the model with assign_mapper

  1. Tim Lesher says:

    It looks as if the link to “previous SQLAlchemy version” is broken.

  2. Julie says:

    My brother suggested I may like this web site. He was once entirely right.
    This submit actually made my day. You can not believe simply how so much time I had spent for this information!

  3. Hello! Someone in my Facebook group shared this website with us so I
    came to take a look. I’m definitely loving the information. I’m bookmarking and will be
    tweeting this to my followers! Wonderful blog and superb style and design.

  4. Darin says:

    I visited plenty of website but I this one this one holds lots of useful points.

  5. The other day, while I was at work, my sister stole my iPad
    and tested to see if it can survive a thirty foot drop, just so
    she can be a youtube sensation. My apple ipad is
    now broken and she has 83 views. I know this is completely off topic but I had
    to share it with someone!

  6. Mittie says:

    naturally like your web site but you need to check the spelling on several of your posts.
    Many of them are rife with spelling problems and I in finding it very
    bothersome to tell the reality on the other hand I’ll definitely come again again.

  7. Your style is very unique compared to other people I’ve read stuff from.
    I appreciate you for posting when you have the opportunity, Guess
    I’ll just bookmark this site.

  8. Amazing blog! Is your theme custom made or did you download it from somewhere?
    A theme like yours with a few simple tweeks would really make my blog stand out.
    Please let me know where you got your theme. Bless you

  9. homepage says:

    If you want to increase your familiarity just keep visiting this web site and be updated wkth the latest gossip posted here.

  10. 2 says:

    Howdy this is somewhat of off topic but I was wanting to know if
    blogs use WYSIWYG editors or if you have to manually code with HTML.
    I’m starting a blog soon but have no coding expertise so I wanted to
    get advice from someone with experience. Any help would be enormously appreciated!

  11. Benjamin says:

    Ƭremendous things here. I aam very happy tto peer yߋur
    article. Thank yoս a lot and I’m taking a llook ahezd to touch
    you. Willl you kindly Ԁrop me a mail?

  12. hey there and thank you for your information – I’ve certainly picked up something new from right here.
    I did however expertise some technical points using this site, as
    I experienced to reload the website many times previous to
    I could get it to load properly. I had been wondering if your web hosting is OK?
    Not that I am complaining, but slow loading instances times will often affect your
    placement in google and can damage your high-quality score if
    advertising and marketing with Adwords. Well I am adding this RSS to my e-mail and could look out for a lot more of your respective exciting content.
    Make sure you update this again very soon.

  13. Heya i’m for the first time here. I found this board and I find It really useful & it helped
    me out much. I hope to give something back and aid others like you aided me.

  14. La qualite des films en streaming sur ces plateformes
    n’est pas optimale: le contenu peut etre de mauvaise qualite et fractionne en plusieurs sequences.
    Vous souhaitez regarder vos films, show et mangas en illimite?

  15. betus scam says:

    Thanks for every other informative web site. Where else may just I get that type of info written in such a perfect manner? I have a venture that I’m simply now running on, and I’ve been at the glance out for such information.

  16. Tobias says:

    Spot on with this write-up, I absolutely think this
    site needs a lot more attention. I’ll probably be returning to read through more,
    thanks for the advice!

  17. I could not refrain frdom commenting. Perfectly written!

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: