Pylons/pyramid — pull request #956 by sergeyv (2013-03-28 22:09:36+00:00)
Title: Docs: SQLAlchemy models do not need an __init__ method

Hi,

In Pyramid documentation and scaffolds all ORM models have an ``__init__`` method which just assigns `name` and `value` to `self.name` and `self.value`.

This method is not needed as SQLAlchemy provides a default constructor which does exactly this (http://docs.sqlalchemy.org/en/rel_0_8/orm/tutorial.html#create-an-instance-of-the-mapped-class)

The practice is kinda ok-ish for a simple model with only two fields, but novice users seem to "scale" the approach linearly to more complex use cases - on stackoverflow I regularly see models like this:

class Event(Base):
__tablename__ = 'event'
record = Column(Integer, Sequence('event_record_seq'), primary_key=True, nullable=False)
fileprefix = Column(String)
date = Column(DateTime, nullable=False)
eventtype = Column(String(3))
filename = Column(String)
memo = Column(String)
project = Column(String)

def __init__(self, fileprefix, date, eventtype, filename, memo, project):
self.fileprefix = fileprefix
self.date = date
self.eventtype = eventtype
self.filename = filename
self.memo = memo
self.project = project

- which is a serious violation of DRY principle and does not compare favourably with, say, Django ORM.

I removed the `__init__` method from the docs (adding a small explanation) and from the scaffolds.