0

I've started to use Datamapper with Padrino and i have some weird issue. The issues is explained below:

1.The code:

 content_type :json
 @fonts = Font.all(:fields=>[:id,:name,:class_name])
 @fonts.to_json
  1. Datamapper executes 3 queries and return me the all result with all fields.

Please see the sql queries that executed:

DEBUG - (0.000087) SELECT id, name, class_name FROM fonts ORDER BY id

DEBUG - (0.000205) SELECT id, post_script_name, designer, license, category, full_name, style, weight, filename, copyright, system_file_path, http_path, ext FROM fonts ORDER BY id

DEBUG - (0.000158) SELECT id, font_face FROM fonts ORDER BY id

Please help me with that Why it's happening ?

Thank you in advance!

Yaniv Vova Alterman
  • 1,660
  • 1
  • 13
  • 11

1 Answers1

0

The solution is:

 content_type :json
 fields_to_select = [:id,:name,:class_name]
 @fonts = Font.all(:fields => fields_to_select).to_json(:only=> fields_to_select)
 @fonts
Yaniv Vova Alterman
  • 1,660
  • 1
  • 13
  • 11