VarboxInternational / varbox

THE Laravel Admin Panel package built by developers, for developers
https://varbox.io
Other
63 stars 13 forks source link

Duplicate model with relationships included #15

Closed andreiamza closed 3 years ago

andreiamza commented 3 years ago

What are you trying to achieve (screenshots might help):

I’m using the HasDuplicates trait on my Post custom entity.
The Post has 2 relations:

How can I configure the duplicate functionality in order to duplicate a post record along with its relationships: comments and author?

I see in your documentation that I have the option of excluding relations, but not to include them.

zbiller commented 3 years ago

The Varbox\Traits\HasDuplicates automatically duplicates all your eloquent model relationships by default, so that's why there's no option to include any relationships to be duplicated, because they all are duplicated by default.

Also, in the event where you don't want certain relations duplicated (such as belongs to relations), you have the option to exclude them (as you already stated): https://varbox.io/docs/2.x/duplicate-records#exclude-relations

So to answer your questions, you don't need to do anything to include your comments and author relations into the duplication functionality, as they will be included by default.


Suggestion: Depending on you database structure and logic architecture, I think you should consider converting the author relation into a belongs to, instead of has one, but that's up to you.