Fix last_post relation; it was totally bogus. veekun-promotions/2010092101
authorEevee <git@veekun.com>
Tue, 21 Sep 2010 07:15:08 +0000 (00:15 -0700)
committerEevee <git@veekun.com>
Tue, 21 Sep 2010 07:15:08 +0000 (00:15 -0700)
splinext/forum/controllers/forum.py
splinext/forum/model/__init__.py

index 0d1207f..5b5ecf9 100644 (file)
@@ -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()) \
         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))
         c.num_threads = threads_q.count()
         try:
             c.skip = int(request.params.get('skip', 0))
index 6dc6bfd..6bfdd1e 100644 (file)
@@ -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')
 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
 # 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')
 
 Post.author = relation(users_model.User, backref='posts')