Skip to content
This repository was archived by the owner on Apr 17, 2018. It is now read-only.
This repository was archived by the owner on Apr 17, 2018. It is now read-only.

properties_to_serialize doesn't use the query's projected fields #30

Description

@jpi

Datamapper allows to restrict the fields to fetch from database via the :fields option, for example :

MyModel.all(:fields => [:id, :name])

However, when serializing such a "restricted" collection, all the fields are serialized, causing new SQL queries to be sent to the database backend.

I find this counter-intuitive :-)

As a quick test, I tried to replace a line in lib/dm-serializer/common.rb :

--- lib/dm-serializer/common.rb.ori 2012-06-11 14:04:32.201075846 +1100
+++ lib/dm-serializer/common.rb 2012-06-11 14:08:03.326296260 +1100
@@ -12,7 +12,7 @@
       only_properties     = Array(options[:only])
       excluded_properties = Array(options[:exclude])

-      model.properties(repository.name).reject do |p|
+      query.fields.reject do |p|
         if only_properties.include? p.name
           false
         else

... and it seems to work for me, both with projected fields and without.

But I'm not sure every DataMapper::Collection has a query.

Would you consider the original behaviour (serialize all model fields) to be expected, or a bug?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions