Skip to main content
Ask A Question
You’re not receiving notifications from this thread.

Compare two active record results along just one column

General • Asked by Michael Victor

I have 3 models - Items, Customizations and Property Maps

Property Maps has a polymorphic association with Items and Customizations

The business logic here is, when listing customizations properties -

If the customization does not have any properties, display the item properties in a normal cell
If the customization has properties that are different from the item, display the list of properties in a "customized-cell" class
If the customization has the same properties as that of the item, display the list of properties in a normal cell.
If both, the customization and item have no customization, display a blank cell.
This is my current implementation of the above

- item_array =
- @item.property_maps.wood_only.each do |property|
    - item_array.push(property.property_id)
- customization_array =
- customization.property_maps.wood_only.each do ||
    - customization_array.push(property.property_id)
- if customization.property_maps.wood_only.present? && item_array.sort != customization_array.sort
    td.customized-cell = {|property| "#{}"}.join(', ')
- elsif @item.property_maps.wood_only.present?
                td = {|property| "#{}"}.join(', ')
            - else 

Is there a way where I can compare the results across a column directly from Active Record? This would save the need for me create new arrays and then compare them.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 30,005+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.