On Tuesday, May 6, 2014 9:57:46 AM UTC-7, Ian Whitney wrote:
>
> Hi Jeremy, thanks for the reply.
>
> You're right that many_to_many is probably wrong. I had been working with 
> one_to_many, but I couldn't get that to work either. So I was trying 
> many_to_many when I wrote my post.
>
> The table I'm working with here stores all previous versions of the row. 
> So there will be multiple rows with the same emplid, acad_career, 
> stdnt_car_number. But they will have different effective dates and 
> effective sequences. (This is PeopleSoft data, btw.)
>
> My eventual goal here is to get the rows with most recent effective date 
> and effective sequence. In straight SQL, that ends up looking like this 
>
> https://gist.github.com/IanWhitney/7ef1335591466e5b1dcf
>

You can probably do something like:

PsAcadProg.one_to_many(:acad_progs, :class=>PsAcadProg,
  :dataset=>proc do |r|
    ds = DB[:asr_warehouse__ps_acad_prog].
      where(:emplid=>:prog__emplid,
        :acad_career=>:prog__acad_career,
        :stdnt_car_nbr=>:prog_stdnt_car_nbr)
    r.associated_dataset.
      from(:asr_warehouse__ps_acad_prog___prog).
      where(ds.where{effdt < `sysdate`}.select{max(:effdt)}=>:effdt,
        ds.where(:effdt=>:prog__effdt).select{max(:effseq)}=>:effseq)
  end)

I didn't test that, but hopefully that or something similar will work.

Thanks,
Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to