Closed keithdoggett closed 3 years ago
If this is approved, I will need to update the wiki and add an example list of this behavior.
I think the ideal case would be to have everything in an app using the same factory. From my experience, I have worked with an app where all boundaries were stored in a projected coordinate system, but some point columns were stored in a geographic column, so the store was helpful in that case.
I believe the most common use case will be to just set a default factory (or use the baked-in defaults), but this does allow flexibility when working with mixed SRIDs or spatial data types.
There used to be a method where a user could define a factory for each column with set_rgeo_factory_for_column
in their models, but that was removed in favor of the store. Not exactly sure if this was done due to technical limitations from an ActiveRecord update or because that caused a lot of repetition if a user just wanted a single factory.
Change the way the
SpatialFactoryStore
looks through its registry. Currently, when registering a factory, theattrs
passed in with the factory are merged with the default params for these fields::geo_type, :has_m, :has_z, :sql_type, :srid
and require an exact match to be returned when queried. This PR changes that behavior to allow fallbacks and less specific entries in theregistry
to be set. Changes theregistry
to anArray
.Now when a factory is queried with a hash of
attrs
, the store will return the factory with the greatest number of matching fields where no mismatches exist. If no matches are found in any factory or no factory can be found without a mismatching attribute, the default factory is returned.This is related to #33.