Skip to content

Instantly share code, notes, and snippets.

@dchandekstark
Last active March 17, 2016 14:41
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 dchandekstark/f507277bd4e1017fd9af to your computer and use it in GitHub Desktop.
Save dchandekstark/f507277bd4e1017fd9af to your computer and use it in GitHub Desktop.
scope :in_collection, ->(collection) {
where(Ddr::Index::Fields::IS_MEMBER_OF_COLLECTION => collection.respond_to?(:id) ? collection.id : collection)
}
scope :having_local_id, ->(local_id) {
where(Ddr::Index::Fields::LOCAL_ID => local_id)
}
def self.having_local_id!(local_id)
results = having_local_id(local_id).to_a
if results.size > 1
raise Error
end
result.first
end
Collection.having_local_id!(local_id)
Item.in_collection(collection).having_local_id!(local_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment