> It might be easier if you provide a concrete example of what you are > trying to achieve (perhaps using the syntax of an existing ORM or using > pseudo-code) and explain how the DAL falls short. >
Using SQLAlchemy as data mapper below. MyItem class (models.myitem): class MyItem(object): def __init__(self, name, description, priority, state, creator, department, notification_users): self.id = None self.name = name self.description = description self.priority = priority self.state = state self.creator = creator self.department = department self.notification_users = notification_users .... (methods that implement MyItem behavior) Similarly, there are User, Department and ItemNotificationRecipient classes. MyItem data mapper (persistence.myitem_data_mapper): metadata = MetaData() # create mapper between MyItem class and my_items table my_items_table = Table('my_items', metadata, Column('id', Integer, primary_key=True), Column('name', String(100)), Column('description', String(400)), Column('priority', Integer), Column('creator_id', ForeignKey('users.id', ondelete='SET NULL')), Column('dept_id', ForeignKey('departments.id', ondelete='SET NULL')), ) mapper(MyItem, my_items_table, properties={ 'notifications' : relationship(ItemNotificationRecipient, backref='my_item', cascade="all,delete") }) Persistence manager code: def init(): db_engine = create_engine(db_server, echo=False) Session = sessionmaker(bind=db_engine) self.session = Session() def add(model_type, *attributes): <implementation> return obj def get_all(model_type): <implementation> return objs def get(model_type, id) <implementation> return obj def search(model_type, filters, fields, order_by) <implementation> return objs def update(obj) self.session.commit() def delete(obj) <implementation> Implementing these operations *in a generic way* to add/delete/update/search data in only one table is rather simple using DAL, foreign keys make it more complicated. There are several algorithms and design patterns to handle this generically (eg http://martinfowler.com/eaaCatalog/ ), but that's exactly what an ORM such as SQLAlchemy does. How would you implement this in web2py? -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.