Self-synchronizing links between objects.
review := SRTestReview new.
book := SRTestBook new.
review book: book.
self assert: review book equals: book.
self assert: book reviews asArray equals: {review}
author := SRTestAuthor new.
book := SRTestBook new.
author books add: book.
self assert: author books asArray equals: {book}.
self assert: book authors asArray equals: {author}
Metacello new
baseline: 'SynchronizedLinks';
repository: 'github://OpenPonk/synchronized-links/repository';
load.
Review has a reference to a Single books.
Review>>book
^ book
Review>>book: aBook
book := SRToOneLink
on: self
slot: #book
oppositeSlot: #reviews
updateFrom: book
to: aBook
Single book can have many Reviews.
Book>>reviews
^ reviews
ifNil: [ reviews := SRToManyLink
on: self
slot: #reviews
oppositeSlot: #book ]
Book>>reviews: aCollection
self reviews
removeAll;
addAll: aCollection
The link will automatically resolve what is on the opposite side, so all variations (1:1, 1:N, N:1, N:M) work automatically.
The objects are internally stored in a OrderedCollection. Support for Set/Bag/OrderedSet will be probably added in the future. Slot implementation will probably also be added in the future.