From 5c2b84869fe3f4bfe41a31ff3968bb13c6d7f868 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Fri, 30 Nov 2012 10:49:06 +0100 Subject: Move DBModel._id -> DBModel.id We were refering to model._id in most of the code base as this is what Mongo uses. However, each use of _id required a) fixup of queries: e.g. what we did in our find() and find_one() functions moving all '_id' to 'id'. It also required using AliasFields to make the ._id attribute available. This all means lots of superfluous fixing and transitioning in a SQL world. It will also not work in the long run. Much newer code already refers to the objects by model.id (e.g. in the oauth plugin), which will break with Mongo. So let's be honest, rip out the _id mongoism and live with .id as the one canonical way to address objects. This commit modifies all users and providers of model._id to use model.id instead. This patch works with or without Mongo removed first, but will break Mongo usage (even more than before) I have not bothered to fixup db.mongo.* and db.sql.convert (which converts from Mongo to SQL) Signed-off-by: Sebastian Spaeth --- mediagoblin/db/sql/base.py | 17 ++--------------- mediagoblin/db/sql/models.py | 10 ---------- 2 files changed, 2 insertions(+), 25 deletions(-) (limited to 'mediagoblin/db/sql') diff --git a/mediagoblin/db/sql/base.py b/mediagoblin/db/sql/base.py index ca0c8166..8aa9cc3a 100644 --- a/mediagoblin/db/sql/base.py +++ b/mediagoblin/db/sql/base.py @@ -42,28 +42,15 @@ class GMGQuery(Query): Session = scoped_session(sessionmaker(query_cls=GMGQuery)) -def _fix_query_dict(query_dict): - if '_id' in query_dict: - query_dict['id'] = query_dict.pop('_id') - - class GMGTableBase(object): query = Session.query_property() @classmethod - def find(cls, query_dict=None): - if query_dict is None: - query_dict = {} - - _fix_query_dict(query_dict) + def find(cls, query_dict): return cls.query.filter_by(**query_dict) @classmethod - def find_one(cls, query_dict=None): - if query_dict is None: - query_dict = {} - - _fix_query_dict(query_dict) + def find_one(cls, query_dict): return cls.query.filter_by(**query_dict).first() @classmethod diff --git a/mediagoblin/db/sql/models.py b/mediagoblin/db/sql/models.py index b48c1fbe..8315d05c 100644 --- a/mediagoblin/db/sql/models.py +++ b/mediagoblin/db/sql/models.py @@ -83,8 +83,6 @@ class User(Base, UserMixin): ## TODO # plugin data would be in a separate model - _id = SimpleFieldAlias("id") - def __repr__(self): return '<{0} #{1} {2} {3} "{4}">'.format( self.__class__.__name__, @@ -161,8 +159,6 @@ class MediaEntry(Base, MediaEntryMixin): # media_data # fail_error - _id = SimpleFieldAlias("id") - def get_comments(self, ascending=False): order_col = MediaComment.created if not ascending: @@ -359,8 +355,6 @@ class MediaComment(Base, MediaCommentMixin): get_author = relationship(User) - _id = SimpleFieldAlias("id") - class Collection(Base, CollectionMixin): __tablename__ = "core__collections" @@ -383,8 +377,6 @@ class Collection(Base, CollectionMixin): return CollectionItem.query.filter_by( collection=self.id).order_by(order_col) - _id = SimpleFieldAlias("id") - class CollectionItem(Base, CollectionItemMixin): __tablename__ = "core__collection_items" @@ -400,8 +392,6 @@ class CollectionItem(Base, CollectionItemMixin): get_media_entry = relationship(MediaEntry) - _id = SimpleFieldAlias("id") - __table_args__ = ( UniqueConstraint('collection', 'media_entry'), {}) -- cgit v1.2.3