All the documentation I've found (pylons web site, examples, etc) tell
the developer to put all this business logic in the controller and
just setup a flimsy old model with the "pass" keyword.  I myself did
the same when first learning pylons.  As my app grew, so did my needs.

I'm trying encapulate all data stuff in the model.  For example, I
have a Book object so it would have methods like get, get_all, recent,
etc.  Those all work fine, but the problem occurs when trying to
create a new Book object.


/models/book.py:
class Book(object):
    def get_all(self):
        query = meta.Session.query(Book).filter_by(user_id=1)
        return query.all()
    def save(self):
        meta.Session.save_or_update(self)
        meta.Session.commit()


/models/__init__.py:
def init_model(engine):
    """
    Setup the model.
    This gets called by lib.app_globals
    """
    print "Initializing model..."
    sm = orm.sessionmaker(autoflush=True, transactional=True,
bind=engine)
    meta.engine = engine
    meta.Session = orm.scoped_session(sm)



Here, my get_all() method works like a charm.  BUT the save() method
gives me this error:
sqlalchemy.exceptions.InvalidRequestError: Class 'type' entity name
'None' has no mapper associated with it

I can see that maybe the model can't save itself and instead the
session should be saving it.  But how do I go about doing that using
this modular structure?

(the suggestion here didn't work for me:
http://groups.google.com/group/pylons-discuss/browse_thread/thread/6ff8f5365414da73/bf384c1d96ea87bd?lnk=gst&q=session+save+in+model+class#bf384c1d96ea87bd)
[I am running Pylons 0.9.7 with SQLAlchemy 0.4.4]



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

Reply via email to