3

I have the following to find posts.

@posts = Post.find(:all, 
:select => "DISTINCT *",
:include => [:user, {:track => :artist}],
:conditions => ["user_id IN (?) AND NOT track_id = ?", users, @track.id],
:group => "track_id", 
:order => 'id desc', 
:limit => '5')

I would like to add the subselect

(SELECT COUNT(*) FROM posts P2 
    WHERE P2.user_id = P1.user_id AND P2.id > P1.id AND P2.track_id <> 34)
 <= 1

in my conditions clause, to restrict the number of posts per user.

How do I set the alias P1 to the "initial" posts table?

Using rails 2.3.11

Jocke
  • 89
  • 2
  • 7

1 Answers1

6

You can add a from parameter:

:from => 'posts P1',

find (ActiveRecord::Base)

alf
  • 18,372
  • 10
  • 61
  • 92