redis-orm 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +22 -6
  2. data/lib/redis/orm/version.rb +1 -1
  3. metadata +1 -1
data/README.md CHANGED
@@ -55,15 +55,11 @@ Like `ActiveRecord`, `redis-orm` defines `created_at` and `updated_at` attribute
55
55
  There are 3 core relationships defined by `redis-orm`: `belongs_to`, `has_one` and `has_many`. They function essentially similar to relations of the same name in ActiveRecord, but it's important to keep in mind that they are specifically designed for Redis, and they have some minor differences.
56
56
 
57
57
  class User < Redis::ORM
58
- attribute :login
59
- attribute :password
60
- has_many :posts
61
- has_one :profile
58
+ has_many :posts, :relation => :user
59
+ has_one :profile, :relation => :user
62
60
  end
63
61
 
64
62
  class Post < Redis::ORM
65
- attribute :subject, "(no subject)"
66
- attribute :body
67
63
  belongs_to :user
68
64
  end
69
65
 
@@ -71,6 +67,26 @@ There are 3 core relationships defined by `redis-orm`: `belongs_to`, `has_one` a
71
67
  belongs_to :user
72
68
  end
73
69
 
70
+ As shwon above, you should usually follow your `has_one` and `has_many` directives with a `relation` option, which matches the corresponding `belongs_to` relation in the other models. Think of it as the `foreign_key` option in ActiveRecord. This option is not strictly required and `redis-orm` will work fine without it, but you may have problems looking up the reverse relations (e.g. the `belongs_to` part) without it.
71
+
72
+ Alternatively, you can specify a `relation` option for the `belongs_to` directive, instead:
73
+
74
+ class User < Redis::ORM
75
+ has_many :posts
76
+ has_one :profile
77
+ end
78
+
79
+ class Post < Redis::ORM
80
+ belongs_to :user, :relation => :posts
81
+ end
82
+
83
+ class Profile < Redis::ORM
84
+ belongs_to :user, :relation => :profile
85
+ end
86
+
87
+ TODO: A future version of this gem will infer the `relation` option from the class name if it omitted.
88
+
89
+
74
90
  #### inference
75
91
 
76
92
  Unlike `ActiveRecord`, `redis-orm` does _not_ infer class names from the relation name. You can give any value you like to the relations. During look-up, class names are retrieved from the object's ID, which (as mentioned) is already maintained for you. So in most cases, you should not have to care about the object's class at all. The only caveat is, all related objects _must_ inherit from `Redis::ORM` so that they can be looked up and deserialized properly.
@@ -3,7 +3,7 @@ class Redis
3
3
  module Version
4
4
  MAJOR = 0
5
5
  MINOR = 0
6
- PATCH = 2
6
+ PATCH = 3
7
7
  PREREL = nil
8
8
 
9
9
  STRING = PREREL ? [MAJOR, MINOR, PATCH, PREREL].join('.') : [MAJOR, MINOR, PATCH].join('.')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: redis-orm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Colin MacKenzie IV