Just write a few helper methods for the common joins...I do something like this:
def billing_headers
DB[:'billing_headers___bh']
end
def join_billing_details(dataset, key_field = :bh__billing)
dataset.join(:billing_details___bd, :bd__billing => key_field)
end
def join_patients(dataset, key_field = :bh__chart)
dataset.join(:patients, :p__chart_number => key_field)
end
def trinity
join_patients join_billing_details billing_headers
end
Every method returns a dataset, so its easy for me to mix and match
and know I have the joins correct. From there, I can filter, group,
select as needed.
dataset = trinity.filter(:entry_date => (Date.civil(2010, 1,
2)..Date.civil(2010, 2, 2)).
select{[:p__chart_number, :bh__total,
sum(:bd__amount).as(:balance), sum(:bd__units).as(:units)]}
(as an example)
Michael
On Thu, Mar 4, 2010 at 2:15 PM, kdf <[email protected]> wrote:
>
> Thanks Jeremy, that works.
>
> I had found a similar example but I was hoping for a simpler
> approach. The majority of my legacy tables have composite keys and
> effective dating so this adds a lot of potential for error in my code.
>
> How hard would it be to write a plugin to generate this code
> automatically ?
>
> --
> You received this message because you are subscribed to the Google Groups
> "sequel-talk" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/sequel-talk?hl=en.
>
>
--
http://codeconnoisseur.org
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sequel-talk?hl=en.