From: Eevee Date: Tue, 21 Sep 2010 07:15:08 +0000 (-0700) Subject: Fix last_post relation; it was totally bogus. X-Git-Tag: veekun-promotions/2010092101^0 X-Git-Url: http://git.veekun.com/zzz-spline-forum.git/commitdiff_plain/758f9ce6c90e033ac9f98735b125c6179f22a943 Fix last_post relation; it was totally bogus. --- diff --git a/splinext/forum/controllers/forum.py b/splinext/forum/controllers/forum.py index 0d1207f..5b5ecf9 100644 --- a/splinext/forum/controllers/forum.py +++ b/splinext/forum/controllers/forum.py @@ -151,7 +151,10 @@ class ForumController(BaseController): threads_q = c.forum.threads \ .join(forum_model.Thread.last_post) \ .order_by(forum_model.Post.posted_time.desc()) \ - .options(joinedload('last_post.author')) + .options( + joinedload('last_post'), + joinedload('last_post.author'), + ) c.num_threads = threads_q.count() try: c.skip = int(request.params.get('skip', 0)) diff --git a/splinext/forum/model/__init__.py b/splinext/forum/model/__init__.py index 6dc6bfd..6bfdd1e 100644 --- a/splinext/forum/model/__init__.py +++ b/splinext/forum/model/__init__.py @@ -83,8 +83,8 @@ Index('thread_position', Post.thread_id, Post.position, unique=True) Forum.threads = relation(Thread, order_by=Thread.id.desc(), lazy='dynamic', backref='forum') Thread.posts = relation(Post, order_by=Post.position.asc(), lazy='dynamic', backref='thread') -Thread.first_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == 1), uselist=False) +Thread.first_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == 1), foreign_keys=[Thread.id], innerjoin=True, uselist=False) # XXX THIS WILL NEED TO CHANGE when posts can be deleted! Or change what 'position' means -Thread.last_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == Thread.post_count), uselist=False) +Thread.last_post = relation(Post, primaryjoin=and_(Post.thread_id == Thread.id, Post.position == Thread.post_count), foreign_keys=[Thread.id, Thread.post_count], innerjoin=True, uselist=False) Post.author = relation(users_model.User, backref='posts')