README.md in relation-0.3.8 vs README.md in relation-0.4.2
- old
+ new
@@ -3,11 +3,11 @@
AFAIK, Relation can replace all kind of relationships in a Rails database.
The gem stores the relationships in a additional table (named
"relations") containing
triples (name of relationship, from:id, to_id).
-No additional column/field is required in a particular tables.
+No additional column/field is required in a particular table.
Adding/removing a relationship do not required a migration.
Is it recommendable? Well, you should know.
In particular, the automagic of Rails associations is not available
for this gem.
@@ -26,43 +26,42 @@
i.e. you are responsible for them.
## Installation
As usual:
+``` ruby
+# Gemfile
+gem "relation"
+```
+and run "bundle install".
- $ [sudo] gem install relation
-
-or:
-
- # Gemfile file
- gem 'relation'
-
- $ bundle
-
Furthermore the association table (an n-ways-join table) must be
installed and migrated.
-You may copy the migration "db/migrate/20150810152808_relation.rb"
+You may copy the migration "./db/migrate/003_create_relations.rb"
from the gem.
+Add indexes if required (benchmarking give clues).
The migration is then done, as usual, by:
$ rails db:migrate
## Usage
In short (order* and user* are instances of ActiveRecords):
- Relation.add order, user
- Relation.add order, user2
- Relation.add order2, user2
+``` ruby
+Relation.add order, user
+Relation.add order, user2
+Relation.add order2, user2
- Relation.references order, User # -> [user, user2]
- Relation.references order2, User # -> [user2]
- Relation.followers Order, user # -> [order]
- Relation.followers Order, user2 # -> [order, order2]
+Relation.references order, User # -> [user, user2]
+Relation.references order2, User # -> [user2]
+Relation.followers Order, user # -> [order]
+Relation.followers Order, user2 # -> [order, order2]
- Relation.delete order2, user2
- Relation.followers Order, user2 # -> [order]
+Relation.delete order2, user2
+Relation.followers Order, user2 # -> [order]
+```
See also the tests.
Dangling, i.e. inaccessible records, references are detected by:
@@ -74,22 +73,33 @@
## Low Level Methods
Above mentioned methods are based on the following low level methods:
- Relation.add_raw(name, from_id, to_id)
- Relation.delete_raw(name, from_id, to_id)
- Relation.references_raw(name, from_id)
- Relation.followers_raw(name, to_id)
+``` ruby
+Relation.add_raw(name, from_id, to_id)
+Relation.delete_raw(name, from_id, to_id)
+Relation.references_raw(name, from_id)
+Relation.followers_raw(name, to_id)
+```
They may be used for relationships which can not be based on the
class name of the ActiveRecords.
Keep in mind that dangling relations must be handled by yourself.
+** Version 4
+
+Version 4.+ is intended for Rails 7.
+
## Rails 6
This gem is intended for Rails 6.
Rails 5 should work fine.
Older Rails versions may use "gem 'relation', '= 0.1.1'".
-## License MIT
+## Miscellaneous
+
+Copyright (c) 2015-2023 Dittmar Krall (www.matiq.com),
+released under the MIT license:
+
+* https://opensource.org/licenses/MIT