openfoodfoundation / openfoodnetwork

Connect suppliers, distributors and consumers to trade local produce.
https://www.openfoodnetwork.org
GNU Affero General Public License v3.0
1.1k stars 714 forks source link

[Spree Upgrade] Replace order.shipping_method_id in basic_enterprise_serializer #2730

Closed luisramos0 closed 6 years ago

luisramos0 commented 6 years ago

app/serializers/api/admin/basic_enterprise_serializer.rb: 1 class Api::Admin::BasicEnterpriseSerializer < ActiveModel::Serializer 2: attributes ... :shipping_method_ids

luisramos0 commented 6 years ago

This serializer is used to inject data into the dom in:

And also used to inject data into this view:

From analysing these parts of the htmland angular code, I havent found any use of shipping_method_ids coming from Api::Admin::BasicEnterpriseSerializer. Please correct me if I am wrong. Anyway, I think we should keep it there as shipping_methods should be part of the basic info about an enterprise.

luisramos0 commented 6 years ago

There's no order.shipping_method_id in this serializer, it's enterprise.shipping_method_ids.

On the way, I have learned some active record magic here: "When you declare a has_many association, the declaring class automatically gains 16 methods related to the association" One of these is collection_singular_ids so In Enterprise has_many :shipping_methods creates shipping_method_ids that is used in the basic_enterprise_serializer.

So, because enterprise.shipping_methods (table distributors_shipping_methods) is still available in 2-0-stable, nothing will change here and there's nothing to do here. Closing issue.