Reputation: 25
for the attachment_type field in the system_files table, a string with the class name is automatically generated. How to set specify class string?
looks like this now:
public $attachOne = [
'main_photo' => [
'System\Models\File',
'delete' => true,
]
];
Upvotes: 0
Views: 73
Reputation: 25
I'm assuming here, but I guess you're not wanting to have the full class stored in in the attachment_type
column of the system_files
table.
What you can do is define a morph map in the boot()
method of your plugin's Plugin.php
file.
So if you had a plugin in the October\Shop
namespace, with a Product
model you could do this.
// Plugin.php
<?php
namespace October\Shop;
use System\Classes\PluginBase;
use October\Rain\Database\Relations\Relation;
class Plugin extends PluginBase
{
public function boot()
{
Relation::morphMap([
'product' => \October\Shop\Models\Product::class,
]);
}
/** The rest of your plugin.php file **/
}
You can read about this in the docs.
OctoberCMS Version 2 docs: Custom Polymorphic Types
OctoberCMS Version 3 docs: Custom Polymorphic Types
Upvotes: 0