Browser fields the id of the object doesn't save

Browser options show list with logo and name, gets attached correctly including logo and name. When you hit refresh the logo stays but the name disappears. Record exists in related table. The id of the object doesn't save into the modules table, stays null. At what point in the Twill system does/should the browser field identifier be saved into the database?
15 Replies
ifox
ifox•2y ago
if the browser uses HasRelated, it only gets saved in the related table and that's all thats needed since it is a polymorphic table. Since you're talking about a column in the module table though, I'm assuming you're looking to save a belongsTo relationship?
devtutorum
devtutorum•2y ago
yes belongsTo
ifox
ifox•2y ago
then you should not configure the browser to use the related table
devtutorum
devtutorum•2y ago
How do I do that?
ifox
ifox•2y ago
in the repository, how are you currently saving the browser? using $relatedBrowsers?
devtutorum
devtutorum•2y ago
<?php namespace App\Repositories; use A17\Twill\Repositories\Behaviors\HandleTranslations; use A17\Twill\Repositories\Behaviors\HandleSlugs; use A17\Twill\Repositories\Behaviors\HandleMedias; use A17\Twill\Repositories\ModuleRepository; use App\Models\Lmspage; class LmspageRepository extends ModuleRepository { use HandleTranslations, HandleSlugs, HandleMedias; public function __construct(Lmspage $model) { $this->model = $model; } protected $relatedBrowsers = ['journeys']; public function afterSave($object, $fields) { $this->updateBrowser($object, $fields, 'journeys'); parent::afterSave($object, $fields); } public function getFormFields($object) { $fields = parent::getFormFields($object); $fields['browsers']['journeys'] = $this->getFormFieldsForBrowser($object, 'journeys'); return $fields; } } Using relatedbrowsers yes
ifox
ifox•2y ago
with this code you're doing it both remove the getFormFields, afterSave, and use the browsers property instead of relatedBrowsers if you're looking to save a belongsTo, you want the id saved in journey_id? Right?
devtutorum
devtutorum•2y ago
Correct!
ifox
ifox•2y ago
so your browser should be called journey and you should have a journey relationship in your model it should work if you do that
devtutorum
devtutorum•2y ago
so in formfield it will be name => journey?
constantvariable.
constantvariable.•15mo ago
Hello, same problem here ;), did you find how to name the browser form field properly for a simple belongsTo relation ? Tx
ifox
ifox•15mo ago
@constantvariable. browser name should be singular name, like the relationship.
constantvariable.
constantvariable.•15mo ago
🤙 I will try I don't get it, sorry… here is my code: Model : Atwork.php
…
use A17\Twill\Models\Behaviors\HasRelated;
…
use HasTranslation, HasSlug, HasMedias, HasRelated;
…
/**
* Get the artist
*/

public function artist()
{
return $this->belongsTo(Artist::class);
}
…
…
use A17\Twill\Models\Behaviors\HasRelated;
…
use HasTranslation, HasSlug, HasMedias, HasRelated;
…
/**
* Get the artist
*/

public function artist()
{
return $this->belongsTo(Artist::class);
}
…
ArtworkRepository.php
…
protected $relatedBrowsers = ['artist'];
…
protected $relatedBrowsers = ['artist'];
artworks/form.blade.php
@formField('browser', [
'moduleName' => 'artists',
'name' => 'artist',
'label' => 'Artiste',
'max' => 1,
])
@formField('browser', [
'moduleName' => 'artists',
'name' => 'artist',
'label' => 'Artiste',
'max' => 1,
])
… in my table artworks, theire is a column with an integer artist_id
ifox
ifox•15mo ago
you should use $browsers not $relatedBrowsers related browsers save in the related table without any relationship on your end
constantvariable.
constantvariable.•15mo ago
Ok ok, it's working
Want results from more Discord servers?
Add your server
More Posts