forked from pjdavis/identity-map
/
README
86 lines (59 loc) · 1.99 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
= IdentityMap
Adds simple hand controlled identity map for ActiveRecord.
== Installing
in Rails 2.3 in config/environment.rb
config.gem 'ar-simple-idmap', :lib => 'identity_map'
in Rails 3 in Gemfile
gem 'ar-simple-idmap', :require => 'identity_map'
== Enabling
To enable in ApplicationController (it is not enabled by default).
class ApplicationController < ActionController::Base
use_identity_map #(installs around filter)
# or use_identity_map :only=>[:index, :show]
# or use_identity_map :except=>[:update]
end
If you decide to disable filter in sub controllers:
class ClientController < ApplicationController
dont_use_identity_map :only=>[:save, :update, :messy_action]
end
Then you should enable identity map for each model class individually:
class TarifPlan < ActiveRecord::Base
use_id_map
has_many :clients
end
class Client < ActiveRecord::Base
use_id_map
belongs_to :tarif_plan
end
You can use identity map for all models by writing in initializer:
class ActiveRecord::Base
use_id_map
end
To enable in rake task or script:
ActiveRecord::Base.with_id_map do
# all things here goes with identity map
end
or equivalently
Client.with_id_map do
# all things here goes with identity map
# not only for Client
end
If you found that identity logic does wrong thing in some particular place,
you could temporary disable it:
ActiveRecord::Base.without_id_map do
# all things here goes without identity map
end
Client.without_id_map do
# all things here goes without identity map
# not only for Client
end
class ClientsController
def strange_action
without_identity_map do
do_strange_things_without_identity_map
end
end
end
== Copyright
inspired by http://github.com/pjdavis/identity-map
Copyright (c) 2010 Sokolov Yura aka funny_falcon, released under the MIT license.