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
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?
yes belongsTo
then you should not configure the browser to use the related table
How do I do that?
in the repository, how are you currently saving the browser?
using
$relatedBrowsers
?<?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 yeswith 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?
Correct!
so your browser should be called
journey
and you should have a journey
relationship in your model
it should work if you do thatso in formfield it will be name => journey?
Hello, same problem here ;), did you find how to name the browser form field properly for a simple belongsTo relation ? Tx
@constantvariable. browser name should be singular name, like the relationship.
🤙 I will try
I don't get it, sorry… here is my code:
Model : Atwork.php
ArtworkRepository.php
artworks/form.blade.php
… in my table artworks, theire is a column with an integer artist_id
you should use $browsers not $relatedBrowsers
related browsers save in the related table without any relationship on your end
Ok ok, it's working