We’re in the process of migrating from the v1.* to v2 for the php / laravel agent.
We have some tables named in a way that don’t adhere to the default doctrine schemas, e.g.
Doctrine\DBAL\Schema\Exception\TableDoesNotExist
There is no table with name "artist_tag_gig_template" in the schema
The actual table name is artist_tag_gigtemplate
Is there a way to annotate this table via the php agent in the same way you can alias a table in Laravel (e.g. protected $table= “artist_tag_gigtemplate” on the Model).
class GigTemplateArtistTag extends Model
{
use HasFactory;
public $table = 'artist_tag_gigtemplate';
...
Not a huge issue as we can migrate and rename the tables but would rather minimise the live service impact; and admittedly this is our issue with the way tables are named.
Hi,
Did you try to rename your collection with this method?
Just to understand, and improve our documentation, do you have some feedback about it ? I ask the question because if you ask the question on the forum, there is a probably an issue with our documentation
And following the ‘Previous/Next’ buttons at the bottom - these don’t appear to follow the same headings as the left menu (e.g. left menu goes Getting started, collection selection, naming conflicts) but the quicklinks at the bottom go straight into Agent Customisation.
So I probably followed the quicklinks at the bottom and not the left submenu, as well as searching for terms like ‘table alias php agent’ or ‘table rename’ not returning that page.
Does this work with EloquentDatasources in terms of the table error?
I’ve tried the below as part of the generated forest_admin config, but the examples suggest to pass in the Model rather than any reference to the underlying table?
I’ve tried variations of the below using the table name, but also the Model just in case (Model name is GigTemplateArtistTag) but it still throws the TableDoesNotExist exception.
use ForestAdmin\AgentPHP\Agent\Builder\AgentFactory;
use ForestAdmin\AgentPHP\DatasourceEloquent\EloquentDatasource;
return static function () {
app()->make(AgentFactory::class)->addDatasource(
new EloquentDatasource(
[
'driver' => env('DB_CONNECTION'),
'host' => env('DB_HOST'),
'port' => env('DB_PORT'),
'database' => env('DB_DATABASE'),
'username' => env('DB_USERNAME'),
'password' => env('DB_PASSWORD'),
// OR
// 'url' => env('DATABASE_URL'),
]
),
[
'rename' => [
'artist_tag_gig_template' => 'artist_tag_gigtemplate'
],
]
);
};
The table names are derived from the Relationships rather than the table themselves, so manually specified the table name in the eloquent relationships themselves in the model.
Yes the $table is defined already on the Model, but Doctrine doesn’t appear to use that at all. We’ve just got around it renaming our tables at database level and defining foreign table names on relationships where we can.