Class | Her::Model::Relation |
In: |
lib/her/model/relation.rb
|
Parent: | Object |
params | [RW] | @private |
parent | [W] |
Create a resource and return it
@example
@user = User.create(:fullname => "Tobias Fünke") # Called via POST "/users/1" with `&fullname=Tobias+Fünke`
@example
@user = User.where(:email => "tobias@bluth.com").create(:fullname => "Tobias Fünke") # Called via POST "/users/1" with `&email=tobias@bluth.com&fullname=Tobias+Fünke`
Fetch specific resource(s) by their ID
@example
@user = User.find(1) # Fetched via GET "/users/1"
@example
@users = User.find([1, 2]) # Fetched via GET "/users/1" and GET "/users/2"
Fetch first resource with the given attributes.
If no resource is found, returns nil.
@example
@user = User.find_by(name: "Tobias", age: 42) # Called via GET "/users?name=Tobias&age=42"
Fetch first resource with the given attributes, or create a resource with the attributes if one is not found.
@example
@user = User.find_or_create_by(email: "remi@example.com") # Returns the first item in the collection if present: # Called via GET "/users?email=remi@example.com" # If collection is empty: # POST /users with `email=remi@example.com` @user.email # => "remi@example.com" @user.new? # => false
Fetch first resource with the given attributes, or initialize a resource with the attributes if one is not found.
@example
@user = User.find_or_initialize_by(email: "remi@example.com") # Returns the first item in the collection if present: # Called via GET "/users?email=remi@example.com" # If collection is empty: @user.email # => "remi@example.com" @user.new? # => true
Fetch a resource and create it if it‘s not found
@example
@user = User.where(:email => "remi@example.com").find_or_create # Returns the first item of the collection if present: # GET "/users?email=remi@example.com" # If collection is empty: # POST /users with `email=remi@example.com`
Fetch a resource and build it if it‘s not found
@example
@user = User.where(:email => "remi@example.com").find_or_initialize # Returns the first item of the collection if present: # GET "/users?email=remi@example.com" # If collection is empty: @user.email # => "remi@example.com" @user.new? # => true