On Wed, Dec 8, 2010 at 2:39 AM, Roger <chiefi...@gmail.com> wrote: > > All of that being said, I solved the problem (possibly improperly) by > doing this: > > 1) Adding a scope definition to feature_types called "with_car", so, > FeatureType.with_car would find me the feature types that, by process, > can exist under the given car. This also uses group to add efficiency > and eliminate duplicates. > > 2) Iterating through each feature_type and pulling potential features > from the already-established self.features array by using a select to > increase efficiency: > > @features = self.features > > @feature_types = FeatureType.with_car(self) > > > @feature_types.each do |feature_type| > feature_type.features = @features.select {|feature| > feature.feature_type_id == feature_type.id} > end > > This iterator reduces the DB load down to two queries (although I KNOW > this could be reduced using a long, handwritten Join -- or the > nested_has_many plugin) > The potential for duplicate feature_types is removed in the > FeatureType.with_car scope. > > If anyone has a solution and can help me do this more the 'rails way,' > that would be excellent. I greatly appreciate the help and wealth of > knowledge already displayed here. > >
I still think it's cleaner to just get all features ordered by feature_type_id and then just do your switching in the view (when feature_id) changes. (You create a new header when you see the feature_id change from the previous iteration.) -- Rick R -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.