Code Monkey home page Code Monkey logo

correlate's Introduction

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" : "<uuid>" },
   { "rel" : "important", "href" : "<uuid>" }
   ...
  ]
  ...
}

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

Installation and dependencies

Use:

  • couchrest 0.33 or later

Development:

  • jeweler

  • rspec

  • activerecord

  • yard

Installation:

$ 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
end

This 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
end

class Document < CouchRest::ExtendedDocument

  property :some_model_id

  view_by :some_model_id
end

class 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 © 2009 Kenneth Kalmer. See LICENSE for details.

correlate's People

Contributors

kennethkalmer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.