lib/jsonapi/resource.rb in jsonapi-resources-0.3.0.pre2 vs lib/jsonapi/resource.rb in jsonapi-resources-0.3.0

- old
+ new

@@ -125,11 +125,11 @@ def _create_has_many_links(association_type, association_key_values) association = self.class._associations[association_type] association_key_values.each do |association_key_value| - related_resource = Resource.resource_for(association.type).find_by_key(association_key_value, context: @context) + related_resource = Resource.resource_for(self.class.module_path + association.type.to_s).find_by_key(association_key_value, context: @context) # ToDo: Add option to skip relations that already exist instead of returning an error? relation = @model.send(association.type).where(association.primary_key => association_key_value).first if relation.nil? @model.send(association.type) << related_resource.model @@ -201,15 +201,10 @@ base._type = type.pluralize.to_sym base.attribute :id, format: :id check_reserved_resource_name(base._type, base.name) - - # If eager loading is on this is how all the resource types are setup - # If eager loading is off some resource types will be initialized in - # _resource_name_from_type - @@resource_types[base._type] ||= base.name.demodulize end def resource_for(type) resource_name = JSONAPI::Resource._resource_name_from_type(type) resource = resource_name.safe_constantize if resource_name @@ -426,13 +421,11 @@ def _updateable_associations associations = [] @_associations.each do |key, association| - if association.is_a?(JSONAPI::Association::HasOne) || association.acts_as_set - associations.push(key) - end + associations.push(key) end associations end def _has_association?(type) @@ -518,9 +511,10 @@ end end def _associate(klass, *attrs) options = attrs.extract_options! + options[:module_path] = module_path attrs.each do |attr| check_reserved_association_name(attr) @_associations[attr] = klass.new(attr, options)