Skip to content

Commit

Permalink
Changes some relationships in test and example models from one-to-man…
Browse files Browse the repository at this point in the history
…y to many-to-one. This fixes an issue with version 0.8.0b2 or greater of SQLAlchemy.
  • Loading branch information
jfinkels committed Jan 16, 2013
1 parent f88d5d8 commit 995754a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Version 0.9.0-dev

Not yet released.

- Changes some dynamically loaded relationships used for testing and in
examples to be many-to-one instead of the incorrect one-to-many. Versions of
SQLAlchemy after 0.8.0b2 raise an exception when the latter is used.
- Fixed issue #117: allow adding related instances on :http:method:`patch`
requests for one-to-one relationships.
- Fixed issue #114: fix bug where string representations of integers were
Expand Down
6 changes: 3 additions & 3 deletions examples/quickstart.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode, unique=True)
birth_date = db.Column(db.Date)
computers = db.relationship('Computer', backref=db.backref('owner',
lazy='dynamic'))


class Computer(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode, unique=True)
vendor = db.Column(db.Unicode)
owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
purchase_time = db.Column(db.DateTime)
owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
owner = db.relationship('Person', backref=db.backref('computers',
lazy='dynamic'))


# Create the database tables.
Expand Down
6 changes: 3 additions & 3 deletions examples/separate_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode, unique=True)
birth_date = db.Column(db.Date)
computers = db.relationship('Computer', backref=db.backref('owner',
lazy='dynamic'))


class Computer(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode, unique=True)
vendor = db.Column(db.Unicode)
owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
purchase_time = db.Column(db.DateTime)
owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
owner = db.relationship('Person', backref=db.backref('computers',
lazy='dynamic'))


# Create the database tables.
Expand Down
4 changes: 2 additions & 2 deletions tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ class LazyComputer(self.Base):
id = Column(Integer, primary_key=True)
name = Column(Unicode)
ownerid = Column(Integer, ForeignKey('lazyperson.id'))
owner = relationship('LazyPerson',
backref=backref('computers', lazy='dynamic'))

class LazyPerson(self.Base):
__tablename__ = 'lazyperson'
id = Column(Integer, primary_key=True)
name = Column(Unicode)
computers = relationship('LazyComputer',
backref=backref('owner', lazy='dynamic'))

class Planet(self.Base):
__tablename__ = 'planet'
Expand Down
7 changes: 4 additions & 3 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,16 +436,17 @@ class Computer(db.Model):
vendor = db.Column(db.Unicode)
buy_date = db.Column(db.DateTime)
owner_id = db.Column(db.Integer, db.ForeignKey('person.id'))
owner = db.relationship('Person',
backref=db.backref('computers',
lazy='dynamic'))

class Person(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.Unicode, unique=True)
age = db.Column(db.Float)
other = db.Column(db.Float)
birth_date = db.Column(db.Date)
computers = db.relationship('Computer',
backref=db.backref('owner',
lazy='dynamic'))

self.Person = Person
self.Computer = Computer

Expand Down

0 comments on commit 995754a

Please sign in to comment.