Embedded Records not working as expected, or at all
Closed this issue · 2 comments
davidwieler commented
Having issues getting embedded records to work at all.
Added a few fields to a homepage:
class HomePage extends Page
{
private static $table_name = 'HomePage';
// Sets database tables for custom fields
private static $db = [
'HeroBannerTitle' => 'Varchar',
'HeroBannerBGImage' => 'Varchar',
'HeroBannerDisplay' => 'Boolean',
'HeroBannerBGImage' => 'Varchar',
];
// Sets the Hero Image database relationships
private static $has_one = [
'HeroBannerBGImage' => Image::class
];
public function getCMSFields()
{
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Hero', CheckboxField::create('HeroBannerDisplay', 'Hide Hero Banner')->setDescription('Check to hide the hero banner'));
$fields->addFieldToTab('Root.Hero', TextField::create('HeroBannerTitle', 'Banner Title'));
$fields->addFieldToTab('Root.Hero', TextField::create('HeroBannerCopy','Banner Copy'));
$fields->addFieldToTab('Root.Hero', $herobanner = UploadField::create('HeroBannerBGImage'));
$herobanner->setFolderName('hero-banners');
return $fields;
}
public function init(){
parent::init();
}
}
And my app.yml file looks like this:
# API access
Image:
api_access: true
File:
api_access: true
Page:
api_access: true
# RestfulAPI config
Colymba\RESTfulAPI\RESTfulAPI:
embedded_records:
Page:
- 'Image'
- 'File'
- 'HeroBannerBGImage'
access_control_policy: 'ACL_CHECK_CONFIG_ONLY'
dependencies:
queryHandler: '%$Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler'
serializer: '%$Colymba\RESTfulAPI\Serializers\DefaultSerializer'
cors:
Enabled: true
Allow-Origin: 'http://mydomain.com'
Allow-Headers: '*'
Allow-Methods: 'OPTIONS, GET'
Max-Age: 86400
# Components config
Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler\DefaultQueryHandler:
dependencies:
deSerializer: '%$Colymba\RESTfulAPI\Serializers\DefaultSerializer'
In the response, the HeroBannerBGImage
is coming back as 11. Which is the proper file ID.
@colymba Any ideas why the embedded_record isn't returning the image itself?
davidwieler commented
also, for some reason api/File
and api/Image
are both saying no model exists.
davidwieler commented
Closing this. Non-issue as we're moving to use a different package as this one doesn't seem to be maintained as much anymore.