Class: ZedDB::ModelAssociations
- Inherits:
-
Object
- Object
- ZedDB::ModelAssociations
- Defined in:
- lib/zeddb/resources/model_associations.rb
Class Method Summary collapse
- .create(zks = {}, &block) ⇒ Object
- .delete(zks = {}, &block) ⇒ Object
-
.get(zks = {}, &block) ⇒ Object
ZedDB Model Associations.
Class Method Details
.create(zks = {}, &block) ⇒ Object
57 58 59 |
# File 'lib/zeddb/resources/model_associations.rb', line 57 def create(zks = {}, &block) Zedkit::Client.crud(:create, 'db/associations', zks, [], &block) end |
.delete(zks = {}, &block) ⇒ Object
61 62 63 |
# File 'lib/zeddb/resources/model_associations.rb', line 61 def delete(zks = {}, &block) Zedkit::Client.crud(:delete, "db/associations/#{zks[:uuid]}", zks, [], &block) end |
.get(zks = {}, &block) ⇒ Object
ZedDB Model Associations
ZedDB models can be associated with each other in predetermined ways. You can create or delete model associations. A model’s associations are listed within its response data set.
To create a new Model Assocation you submit the required parameters of the association type with the model UUIDs that you are creating an association between. Whatever items you send within the :association Hash are passed through to the ZedAPI untouched. There is no client side validation within this gem.
Associations can be confusing to create, given that the order is arbitary. But you would read an association as Model B belongs to Model A. So, to create a belongs_to association. You would be using the resource location based on Model B, creating an association to Model A, with “first” and “second” labels as you read the association aloud.
ZedDB::ModelAssociations.create(:user_key => user['user_key'],
:association => { :first => model_b['uuid'],
:code => 'BT', :inverse => 'HM', :second => model_b['uuid] })
To delete a Model Association:
ZedDB::ModelAssociations.delete(:user_key => user['user_key'], :uuid => association['uuid])
From each of these requests the Zedkit::Client class will return a response hash for your reference, if needed, or as applicable to the request. If there was a HTTP 401 or 404 you will get a nil response. This indicates a security failure or that an UUID is incorrect, not attached the user’s account, or non-existent.
For each request you can also pass a block to process the response directly:
ZedDB::ModelAssociations.delete(:user_key => user['user_key'], :uuid => association['uuid]) do |result|
end
53 54 55 |
# File 'lib/zeddb/resources/model_associations.rb', line 53 def get(zks = {}, &block) Zedkit::Client.crud(:get, "db/associations/#{zks[:uuid]}", zks, [], &block) end |