i can do company.products .count and get back the product count
what i’d like to know is if there is a more elegant way to get the
number of parts for a given company outside of iterating through each
product, counting its parts and then summing that number.
the solution i have now works. i was just wondering if there was a more
elegant way of going about it.
i can do company.products .count and get back the product count
what i’d like to know is if there is a more elegant way to get the
number of parts for a given company outside of iterating through each
product, counting its parts and then summing that number.
the solution i have now works. i was just wondering if there was a more
elegant way of going about it.
thanks,
binh
Within rails? probably not.
You could, however, create a view in the target database and then use
that to return the desired values. I
Or, if this type of reporting is a frequent requirement, and the the
parts per product is usually stable, then it might be worth while to
have a regularly scheduled or dynamically calculated roll-up of the part
count into a field in the product table and then report on that.
product, counting its parts and then summing that number.
Give Company a has_many :through relation to Part, and then you’ll be
able to do company.parts.count.
///ark
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.