You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Plugin for the PaperTrail gem to track and reify associations
5
+
Plugin for the [PaperTrail](https://github.com/paper-trail-gem/paper_trail.git) gem to track and reify associations.
6
+
7
+
**PR's will happily be accepted**
8
+
9
+
This gem was extracted from PaperTrail in v10 to simplify things in PaperTrail and association tracking seperately.
10
+
At this time, `paper_trail` has a runtime dependency on this gem and will keep running the existing tests related
11
+
to association tracking. This arrangement will be maintained for a few years, if practical.
12
+
13
+
A little history lesson, discussed as early as 2009, and first implemented in late 2014, association
14
+
tracking was part of PT core until 2018 as an experimental feature and was use at your own risk. This gem now
15
+
maintains a list of known issues and we hope the community can help remove some of them via PR's.
6
16
7
17
## TODO
8
18
9
19
- Continue removing most-non association specs
10
-
- Improve Readme
11
20
- Add consolidated list of paper trail plugins to paper_trail core readme
12
21
13
22
## Table of Contents
14
23
15
24
<!-- toc -->
16
25
17
-
-[1. Install](#1-install)
18
-
-[2. Associations](#2-associations)
19
-
-[3. Known Issues](#3-known-issues)
20
-
-[Articles](#articles)
26
+
-[Install](#install)
27
+
-[Associations](#associations)
28
+
-[Known Issues](#known-issues)
21
29
-[Contributing](#contributing)
22
30
-[Credits](#credits)
23
31
24
32
<!-- tocstop -->
25
33
26
-
### 1. Install
27
-
28
-
1. Add to your `Gemfile`.
34
+
# Install
29
35
30
36
```ruby
37
+
# Gemfile
38
+
31
39
gem 'paper_trail'# Requires v10+
32
40
gem 'paper_trail-association_tracking'
33
41
```
34
42
35
-
### 2. Association Tracking
43
+
# Association Tracking
36
44
37
45
This plugin currently can restore three types of associations: Has-One, Has-Many, and
38
46
Has-Many-Through. In order to do this, you will need to do two things:
@@ -83,7 +91,7 @@ t.amount # 100
83
91
t.location.latitude # 12.345
84
92
```
85
93
86
-
If the parent and child are updated in one go, PaperTrail can use the
94
+
If the parent and child are updated in one go, PaperTrail-AssociationTracking can use the
87
95
aforementioned `transaction_id` to reify the models as they were before the
88
96
transaction (instead of before the update to the model).
89
97
@@ -101,7 +109,7 @@ t.amount # 100
101
109
t.location.latitude # 12.345, instead of 54.321
102
110
```
103
111
104
-
By default, PaperTrail excludes an associated record from the reified parent
112
+
By default, PaperTrail-AssociationTracking excludes an associated record from the reified parent
105
113
model if the associated record exists in the live model but did not exist as at
106
114
the time the version was created. This is usually what you want if you just want
107
115
to look at the reified version. But if you want to persist it, it would be
@@ -133,118 +141,113 @@ widget_0.save!
133
141
widget.reload.wotsit # nil
134
142
```
135
143
136
-
#### 3. Known Issues
144
+
# Known Issues
145
+
146
+
Associations have the following known issues, in order of descending importance. Use in Production at your own risk.
147
+
148
+
**PR's for these issues will happily be accepted**
137
149
138
-
Associations are an **experimental feature** and have the following known
139
-
issues, in order of descending importance. Use in Production at your own risk.
150
+
If you notice anything here that should be updated/removed/edited feel free to create an issue.
140
151
141
-
1. PaperTrail only reifies the first level of associations.
152
+
1. PaperTrail-AssociationTracking only reifies the first level of associations.
142
153
1. Sometimes the has_one association will find more than one possible candidate and will raise a `PaperTrail::Reifiers::HasOne::FoundMoreThanOne` error. For example, see `spec/models/person_spec.rb`
143
-
- If you are not using STI, you may want to just assume the first result (of multiple) is the correct one and continue. Versions pre v8.1.2 and below did this without error or warning. To do so add the following line to your initializer: `PaperTrail.config.association_reify_error_behaviour = :warn`. Valid options are: `[:error, :warn, :ignore]`
154
+
- If you are not using STI, you may want to just assume the first result (of multiple) is the correct one and continue. PaperTrail <= v8 did this without error or warning. To do so add the following line to your initializer: `PaperTrail.config.association_reify_error_behaviour = :warn`. Valid options are: `[:error, :warn, :ignore]`
144
155
- When using STI, even if you enable `:warn` you will likely still end up recieving an `ActiveRecord::AssociationTypeMismatch` error.
Not compatible with [transactional tests](https://github.com/rails/rails/blob/591a0bb87fff7583e01156696fbbf929d48d3e54/activerecord/lib/active_record/fixtures.rb#L142), aka. transactional fixtures.
147
158
1. Requires database timestamp columns with fractional second precision.
148
159
- Sqlite and postgres timestamps have fractional second precision by default.
149
160
[MySQL timestamps do not](https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html). Furthermore, MySQL 5.5 and earlier do not
150
161
support fractional second precision at all.
151
162
- Also, support for fractional seconds in MySQL was not added to
152
163
rails until ActiveRecord 4.2 (https://github.com/rails/rails/pull/14359).
153
-
1. PaperTrail can't restore an association properly if the association record
164
+
1. PaperTrail-AssociationTracking can't restore an association properly if the association record
154
165
can be updated to replace its parent model (by replacing the foreign key)
155
-
1. Currently PaperTrail only supports a single `version_associations` table.
166
+
1. Currently PaperTrail-AssociationTracking only supports a single `version_associations` table.
156
167
Therefore, you can only use a single table to store the versions for
157
168
all related models. Sorry for those who use multiple version tables.
158
-
1. PaperTrail relies on the callbacks on the association model (and the :through
169
+
1. PaperTrail-AssociationTracking relies on the callbacks on the association model (and the :through
159
170
association model for Has-Many-Through associations) to record the versions
160
171
and the relationship between the versions. If the association is changed
161
172
without invoking the callbacks, Reification won't work. Below are some
See [PT Issue #113](https://github.com/paper-trail-gem/paper_trail/issues/113) for a discussion about this.
228
232
229
-
At this time during `reify` any STI `has_one` associations will raise a `PaperTrail::Reifiers::HasOne::FoundMoreThanOne` error. See https://github.com/airblade/paper_trail/issues/594
230
233
231
-
Something to note though, is while the PaperTrail gem supports [Single Table Inheritance](http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord::Base-label-Single+table+inheritance), I dont recommend STI ever. Your better off rolling your own solution rather than using STI.
234
+
### Regarding ActiveRecord Single Table Inheritance (STI)
232
235
236
+
At this time during `reify` any STI `has_one` associations will raise a `PaperTrail::Reifiers::HasOne::FoundMoreThanOne` error. See [PT Issue #594](https://github.com/airblade/paper_trail/issues/594)
233
237
234
-
## Articles
238
+
Something to note though, is while the PaperTrail gem supports [Single Table Inheritance](http://api.rubyonrails.org/classes/ActiveRecord/Base.html#class-ActiveRecord::Base-label-Single+table+inheritance), I do NOT recommend STI ever. Your better off rolling your own solution rather than using STI.
235
239
236
-
*[Example Title](the_article_url),
237
-
[Example Author](the_author_url), 2018-05-18
240
+
# Contributing
238
241
239
-
## Contributing
242
+
See the paper_trail [contribution guidelines](https://github.com/paper-trail-gem/paper_trail/blob/master/.github/CONTRIBUTING.md)
240
243
241
-
See our [contribution guidelines](https://github.com/paper-trail-gem/paper_trail/blob/master/.github/CONTRIBUTING.md)
244
+
# Credits
242
245
243
-
## Credits
246
+
Plugin authored by [Weston Ganger](https://github.com/westonganger) & Jared Beck
244
247
245
-
Maintained by [Weston Ganger](https://github.com/westonganger)
248
+
Maintained by [Weston Ganger](https://github.com/westonganger) & [Jared Beck](https://github.com/jaredbeck)
246
249
247
-
Associations code originally authored by Ben Atkins, Jared Beck, & more
250
+
Associations code originally contributed by Ben Atkins, Jared Beck, Andy Stewart & more
0 commit comments