InlineRepeater deleting data on related Model entries

I'm using an InlineRepeater to add relations with pivot data between two Repositories. The relations and pivot data are being stored as expected, but I just realized that when I update the entry, it is also deleting Media and Block data for the related model entry. I just lost a good bit of work to this. I have a repository Location and a repository Taxa, with a location_taxa many-to-many pivot table to connect the two. In the Taxa model, I've created this relation:
public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->orderByPivot('position')
->withPivot(['details']);
}
public function locations(): BelongsToMany
{
return $this->belongsToMany(Location::class)
->orderByPivot('position')
->withPivot(['details']);
}
In my TaxaController, I've configured the InlineRepeater as such:
Fieldset::make()->title('Locations')->id('locations')->fields([
InlineRepeater::make()
->name('location_taxa')
->label('Locations')
->allowBrowser()
->relation(Location::class)
->fields([
Input::make()
->name('title')
->translatable()
->disabled(),

Wysiwyg::make()
->name('details')
->translatable()
,

]),
]),
);
Fieldset::make()->title('Locations')->id('locations')->fields([
InlineRepeater::make()
->name('location_taxa')
->label('Locations')
->allowBrowser()
->relation(Location::class)
->fields([
Input::make()
->name('title')
->translatable()
->disabled(),

Wysiwyg::make()
->name('details')
->translatable()
,

]),
]),
);
This stores the relationship and details in the pivot table as expected. I'm not sure why it's also accidentally destroying the data
10 Replies
daniel
danielOP10mo ago
This is a pretty devastating blocker for this project and so any help is greatly appreciated.
daniel
danielOP10mo ago
Looking at the payload from saving the Taxa, I can only guess it's because the blocks and medias fields are empty here, but I don't know how I would go about changing this behavior. Why is it sending/saving more than just the pivot field(s)?
No description
ifox
ifox10mo ago
Hey @daniel Twill 3.1 is out now so I'll try to spend more time to help here. Any chance you could provide a quick repro for this? That'll help expedite getting the support you need if you can Maybe that's not needed after reviewing everything you shared I see what's going on
daniel
danielOP10mo ago
Ok great @ifox any more thoughts on this one?
ifox
ifox10mo ago
@daniel you're using updateRepeaterWithPivot, right?
daniel
danielOP10mo ago
@ifox yeah, updateRepeaterWithPivot and getFormFieldForRepeaterWithPivot
No description
No description
ifox
ifox10mo ago
ok, so our implementation has only been used for simple related models where all the fields from that model would be in the repeater (not just the title like you have). As in, the associated content is created inline and the related module isn't exposed standalone in the CMS where it could have medias and blocks etc... since you only ever want to update the pivot fields can you try to comment out this line https://github.com/area17/twill/blob/063b4bbbe2b133f48008de250be8f767ce2350c1/src/Repositories/Behaviors/HandleRepeaters.php#L219? If that works you can override the function in your project for now and we could just add an option or another method to achieve your use case. It makes a lot of sense to me, we just haven't structured our form that way
GitHub
twill/src/Repositories/Behaviors/HandleRepeaters.php at 063b4bbbe2b...
Twill is an open source CMS toolkit for Laravel that helps developers rapidly create a custom admin console that is intuitive, powerful and flexible. Chat with us on Discord at https://discord.gg/c...
ifox
ifox10mo ago
To clarify, the inline repeater as it is currently implemented is meant to write into the related model too (hence inline), not just the pivot but we can easily add what you need to only edit the pivot
daniel
danielOP10mo ago
this worked! thank you so much. just curious -- is there another method that would be more "standard" for my use case? or am I just doing something that hadn't been considered before? either way, really glad that there's a workaround for it. eventual official support would of course be awesome. thank you again!
ifox
ifox10mo ago
Awesome, yeah it's just that it hasn't been considered It will! And I'll let you know when you can remove your override
Want results from more Discord servers?
Add your server