Module: Daylight::Collection
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/daylight/collection.rb
Overview
Alternate collection methods for first_or_create
, first_or_initialize
.
Used to split the original_params
into known attributes and query params added by ResourceProxy.
Parameters not added by ResourceProxy will still be merged into the supplied attributes. This is the current ActiveResource behavior.
Parameters that contain known attributes (ie. :filter
) will also be merged with the supplied attributes. The query parameters (ie. :scopes
) will be set on prefix_options
For example:
users = User.find(:all, params: {
filters: {last_name: {'Bonzai'}},
scopes: ['planet_ten'],
band: 'Hong Kong Cavaliers'
})
Return all Users in the band ‘Hong Kong Cavaliers’ where their last name is ‘Bonzai’. If a User with first name ‘Buckaroo’ does not exist:
users.first_or_create(first_name: 'Buckaroo')
Or:
users.first_or_initialize(first_name: 'Buckaroo').save
Will issue the following request where the band is kept as a query parameter and the contents of the filter
paramter are merged with the attributes:
POST: /api/v1/users.json?scopes[]=planet_ten
DATA: {"user":{"first_name":"Buckaroo", "last_name":"Bonzai", "band":"Hong Kong Cavaliers"}}
See: ActiveResource::Collection