README.md in related-0.1 vs README.md in related-0.2

- old
+ new

@@ -54,14 +54,57 @@ To get the results from a query: node.outgoing(:friends).to_a node.outgoing(:friends).count (or .size, which is memoized) -You can also do set operations, like union, diff and intersect (not implemented yet): +You can also do set operations, like union, diff and intersect: node1.outgoing(:friends).union(node2.outgoing(:friends)) node1.outgoing(:friends).diff(node2.outgoing(:friends)) node1.outgoing(:friends).intersect(node2.outgoing(:friends)) + +Relationships are sorted based on when they were created, which means you can +paginate them: + + node.outgoing(:friends).relationship.per_page(100).page(1) + node.outgoing(:friends).relationship.per_page(100).page(rel) + +The second form paginates based on the id of the last relationship on the +previous page. Useful for cases where explicit page numbers are not +appropriate. + +Pagination only works for relationships. If you want to access nodes directly +without going through the extra step of iterating through the relationship +objects you will only get random nodes. Thus you can use .limit (or .per_page) +like this to get a random selection of nodes: + + node.outgoing(:friends).nodes.limit(5) + +Follower +-------- + +Related includes a helper module called Related::Follower that you can include +in your node sub-class to get basic Twitter-like follow functionality: + + class User < Related::Node + include Related::Follower + end + + user1 = User.create + user2 = User.create + + user1.follow!(user2) + user1.unfollow!(user2) + user2.followers + user1.following + user1.friends + user2.followed_by?(user1) + user1.following?(user2) + user2.followers_count + user1.following_count + +The two nodes does not need to be of the same type. You can for example have +a User following a Page or whatever makes sense in your app. Development ----------- If you want to make your own changes to Related, first clone the repo and