我已经开始在Padrino中使用Datamapper,我有一些奇怪的问题。 问题解释如下:
1.代码:
content_type :json
@fonts = Font.all(:fields=>[:id,:name,:class_name])
@fonts.to_json
请参阅执行的sql查询:
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
< / p>
DEBUG - (0.000158)SELECT id
,font_face
FROM fonts
ORDER BY id
请帮助我 它为什么会发生?
提前谢谢!
答案 0 :(得分: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