Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kennethkalmer/correlate
An experiment in expressing relationships between CouchRest documents and ActiveRecord models
https://github.com/kennethkalmer/correlate
Last synced: about 15 hours ago
JSON representation
An experiment in expressing relationships between CouchRest documents and ActiveRecord models
- Host: GitHub
- URL: https://github.com/kennethkalmer/correlate
- Owner: kennethkalmer
- License: mit
- Created: 2009-12-10T07:38:21.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2009-12-15T13:24:10.000Z (almost 15 years ago)
- Last Synced: 2024-04-16T05:35:24.324Z (7 months ago)
- Language: Ruby
- Homepage:
- Size: 111 KB
- Stars: 14
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- Changelog: History.txt
- License: LICENSE
Awesome Lists containing this project
README
= Correlate
Correlate is an experiment in loosely expressing relationsips between documents
stored in CouchDB using couchrest.Correlate stores all the relationships in an array of links, similar to the link
elements found in HTML:{
...
"links" : [
{ "rel" : "another_doc", "href" : "" },
{ "rel" : "important", "href" : "" }
...
]
...
}Inspired by looking for ways to express the loosened relationships that exists
between documents inside CouchDB, but to not mimic the nature of an RDBMS.IMPORTANT:
Unlike relational-thinking, all the relationships are expressed on the given
object itself, not its correlated objects. Correlate does support recipocal
correlations which, when enabled for a correlation, updates the links on both
objects.== Documentation
* http://rdoc.info/projects/kennethkalmer/correlata
* spec directory== Installation and dependencies
Use:
* couchrest 0.33 or later
Development:
* jeweler
* rspec
* activerecord
* yardInstallation:
$ gem install correlate
Correlate does not depend on ActiveRecord and can be safely used in any project
that doesn't use ActiveRecord.== Usage
require 'correlate'
class MyDocument < CouchRest::ExtendedDocument
include Correlate
related_to do
some :other_documents, :class => 'OtherDocument', :rel => 'other_doc'
end
endThis sets up a +links+ property on the document, with some accessors for loading
and ammending relationships:my_doc = MyDocument.new
my_doc.other_documents << other_document_instance
my_doc.other_documents #=> [ other_document_instance ]
== Associations with ActiveRecord models
When transitioning from ActiveRecord to CouchDB it is inevitable that relationships
will exist across the boundaries of each database. Correlate helps you to express
these relationships:== CouchDB to ActiveRecord
Pretty much the same as the examples above:
class MyDocument < CouchRest::ExtendedDocument
include Correlate
related_to do
a :model, :class => 'Model', :rel => 'model'
end
end== ActiveRecord to CouchDB
When using an 'a' relationship, you don't need to specify any additional
information, but when specifying a 'some' relationship you'll want to supply
the name of the view.class SomeModel < ActiveRecord::Base
include Correlate
related_to do
some :documents, :class => 'Document', :view => 'some_model_id', :key => :id
some :notes, :class => 'Note', :rel => 'some_model'
end
endclass Document < CouchRest::ExtendedDocument
property :some_model_id
view_by :some_model_id
endclass Note < CouchRest::ExtendedDocument
include Correlate
related_to do
a :some_model, :class => 'SomeModel', :rel => 'some_model'
end
end== Status
This project is highly experimental, but is in use in a few applications in one
form or another.== Note on Patches/Pull Requests
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a
future version unintentionally.
* Commit, do not mess with rakefile, version, or history.
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
* Send me a pull request. Bonus points for topic branches.== Copyright
Copyright (c) 2009 Kenneth Kalmer. See LICENSE for details.