As soon as I use Model.find(:all, :include => [...], :limit => 3) I
loose associations and can''t do :conditions on joined tables.
I''m not
able to do pagination in such association.
Only solution I came up with is this beast:
# I set up a paginator:
@reos_pages = Paginator.new self,
Reo.count(conds.join('' AND ''),
''JOIN lang_reos ON reos.id =
reo_id''),
RECS_PER_PAGE,
params[:page]
# then I find out which ids count on for current page
limit, offset = @reos_pages.current.to_sql
reo_ids = Reo.find :all, :conditions => conds.join('' AND
''),
:joins => ''JOIN lang_reos ON reos.id =
reo_id'',
:order => ''ref_id ASC'',
:limit => limit, :offset => offset
# and finally I can use :include
@reos = Reo.find reo_ids.collect { |r| r.reo_id },
:conditions => ([''primary_pict=1''] +
conds).join('' AND ''),
:include => [:lang_reos, :pictures, :location],
:order => ''ref_id ASC''