I'm trying to restrict the number of JSON fields that are returned by a 
Sinatra app's endpoint.

The model:

class FooBar< Sequel::Model    
    plugin :json_serializer
   ...
end

If I filter the model using a WHERE statement, which returns an array, the 
fields aren't restricted:

    @results = FooBar

    if params[:a] # => 'foo'
        @results = @results.where( a: params[:a] )
    end

    @results.all.to_json(only: [:a,:b])

    {
        "a": "foo",
        "b": "bar",
        "c": "baz",
        "d": "xxx"
    }

          I've also tried @results.naked.to_json() with the same results.

If I select using the primary key, however, the columns are restricted:

    FooBar['foo'].to_json(only: [:a,:b])

    {
        "a": "foo",
        "b": "bar"
    }

Are arrays of instances supported?

I'm using the tiny_tds gem to connect to MSSQL, if that makes a difference.

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/60578ac5-7a26-40e5-8593-9ab631a117cfn%40googlegroups.com.

Reply via email to