Module: QuickbaseRecord::Queries
- Extended by:
- ActiveSupport::Concern
- Includes:
- Client
- Included in:
- Model
- Defined in:
- lib/quickbase_record/queries.rb
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- UNWRITABLE_FIELDS =
['dbid', 'id', 'date_created', 'date_modified', 'record_owner', 'last_modified_by']
Instance Method Summary collapse
- #delete ⇒ Object
-
#save ⇒ Object
INSTANCE METHODS.
- #update_attributes(attributes = {}) ⇒ Object
Methods included from Client
Instance Method Details
#delete ⇒ Object
189 190 191 192 193 |
# File 'lib/quickbase_record/queries.rb', line 189 def delete return false unless self.id successful = qb_client.delete_record(self.class.dbid, self.id) return successful ? self.id : false end |
#save ⇒ Object
INSTANCE METHODS
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/quickbase_record/queries.rb', line 172 def save current_object = {} self.class.fields.each do |field_name, fid| current_object[fid] = public_send(field_name) unless UNWRITABLE_FIELDS.include?(field_name.to_s) end current_object.delete_if { |key, value| value.nil? } if self.id qb_client.edit_record(self.class.dbid, self.id, current_object) else self.id = qb_client.add_record(self.class.dbid, current_object) end return self end |
#update_attributes(attributes = {}) ⇒ Object
195 196 197 198 199 200 201 202 203 204 205 206 207 |
# File 'lib/quickbase_record/queries.rb', line 195 def update_attributes(attributes={}) return false if attributes.blank? self.assign_attributes(attributes) updated_attributes = {} attributes.each { |field_name, value| updated_attributes[self.class.convert_field_name_to_fid(field_name)] = value } updated_attributes.delete_if { |key, value| value.nil? } if self.id qb_client.edit_record(self.class.dbid, self.id, updated_attributes) else self.id = qb_client.add_record(self.class.dbid, updated_attributes) end return self end |