Skip to content

Instantly share code, notes, and snippets.

@jambun
Created April 17, 2020 04:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jambun/4ffcee180fb490dec60336ee8e7ee138 to your computer and use it in GitHub Desktop.
Save jambun/4ffcee180fb490dec60336ee8e7ee138 to your computer and use it in GitHub Desktop.
plausible?
def self.attach_raps(model_class, ids, rap)
objs = model_class.filter(:id => ids).all
jsons = model_class.sequel_to_jsonmodel(objs)
RAP.filter(:"#{model_class.table_name}_id" => ids).update(RAPs.supported_models.map {|model| [:"#{model.table_name}_id", nil]}.to_h)
objs.zip(jsons).each do |obj, json|
json['rap_attached'] = rap.to_hash
RAP.create_from_json(JSONModel(:rap).from_hash(rap), {:"#{obj.class.table_name}_id" => obj.id})
obj.mark_as_system_modified
force_unpublish_for_restricted(model_class, obj.id)
end
end
@jambun
Copy link
Author

jambun commented Apr 17, 2020

line 8 is cruft

@jambun
Copy link
Author

jambun commented Apr 17, 2020

in fact don't need to be getting jsons and zipping anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment