Has_many :through and outer join problem

I’m running into a performance problem and I’m wondering if there’s a
solution.

I’ve got three tables: clients, fields, and values. Clients have many
values, and they also have many fields through the values.

I need an easy way to map the entire collection of fields to their
values (regardless of whether they have a value) for any given client.

As it stands, the only way I can get to the fields table is through the
values table, and if the value is not present for that particular
client, I don’t get the info on that particular row.

What I’ve been doing while I work this out is get the entire fields
collection and iterate over the client’s values, asking if the value’s
field ID matches the particular field we’re looking at. The problem is
that it’s slow and not at all optimal. I’d much rather have a method in
my model to merge the entire collection of fields with the contact’s
values, or even better, a way to pull it back to the database level and
get the entire resultset there.

Any ideas?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs