nova-duplicate-field icon indicating copy to clipboard operation
nova-duplicate-field copied to clipboard

Allow resource relations to be maintained or duplicated

Open ns139426 opened this issue 6 years ago • 7 comments

For duplicating resources with ownership relations, I found it useful to be able to attach the previous relations to the new model. This could be achieved by overloading the replicate() method on the model but this seemed like a more elegant solution.

For my purposes I'd used relationsDuplicate and relationsMaintain for clarity in the options but kept breaking changes out of this PR.

ns139426 avatar Jun 29 '19 07:06 ns139426

Thanks for the contribution - a couple of questions:

Does this work for belongsToMany as well?

What's the intended difference between "maintains" and "relations"?

jackabox avatar Jul 08 '19 11:07 jackabox

It works for the belongToMany relationship that I use but my testing probably can't be described as extensive at this point.

As mentioned, the wording is not ideal for the option but I was conscious of avoiding a breaking change. The intention for maintains was to persist/maintain an existing relationship rather than duplicating the records. If many teams owned a quiz and the quiz had many questions, the ideal operation for replication would likely be to maintain the existing ownership relationship so the teams retain access to the correct quizzes but that the questions are duplicated so that they can be modified separately.

ns139426 avatar Jul 08 '19 16:07 ns139426

I'll need to spin this up and test it quickly.

I believe we need another term other than 'Maintain'. For example 'Preserve Relationships'. preserveRelationships I'd prefer it to be obvious where possible.

jackabox avatar Jul 12 '19 08:07 jackabox

Absolutely, if a breaking change was acceptable I’d suggest preserveRelationships and duplicateRelationships as clear and obvious names. It would be trivial to add support for duplicateRelationships and maintain the existing relationship option but the code obviously gets a little muddier.

ns139426 avatar Jul 12 '19 19:07 ns139426

Going to try to get this into a v1 release to allocate for the breaking change. Haven't forgot just not got around yet.

jackabox avatar Aug 12 '19 15:08 jackabox

Might be worth integrating this into #20 and using one solid logic (with backward compatibility for the different relation types)

jackabox avatar Sep 03 '19 09:09 jackabox

Might be worth integrating this into #20 and using one solid logic (with backward compatibility for the different relation types)

Definitely. I can wait until the requested abstraction work is done there and then look to add these changes in a sensible way.

ns139426 avatar Sep 11 '19 18:09 ns139426