Conditional join selection with active record

hello list,

i’m searching for an implementation of the following sql statement:

SELECT inserent.* FROM inserent
join
(select objpriv.maknr from objpriv
where objpriv.bankkto like ‘593%’ and objpriv.zahlart = ‘B’
group by objpriv.maknr) o on o.maknr = inserent.insnr

ORDER BY
inserent.AENDDATUM desc

evidently, i solved my problem with

@advertisers = Advertiser.paginate( :select => “inserent.*”, :order =>
“inserent.AENDDATUM desc”, :from => “inserent join (select
objpriv.maknr from objpriv where objpriv.bankkto like ‘#{query}’ and
objpriv.zahlart = ‘B’ group by objpriv.maknr) o on o.maknr =
inserent.insnr”)

but, the pagination is broken.
i know i’m abusing the from parameter for my needs

what’s the way to implement it?

thanks for all your help

best regards

On 15 Oct 2008, at 10:41, inriz wrote:

but, the pagination is broken.
i know i’m abusing the from parameter for my needs

Use the :joins parameter ?

Fred