Videos -> Module Development -> Module Setup and Scaffolding - unable to create pivot table

endder - 9 months ago

Hi All, just running through the training videos and current can't work out what I am doing wrong.

when I run:

php artisan addon:install videos 

everything runs fine, but the table 'default_videos_videos_categories' doesn't get created. I ran through the video 2 more times to see if I had missed something but can't see anything I had missed.

Did anyone else have this issue?

Thanks

ryanthompson - 9 months ago

Can you post your applicable fields and stream migrations? Let's take a look at what you've got ^_^

endder - 9 months ago

AnomalyModuleVideosCreateVideosFields

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;
use Anomaly\VideosModule\Category\CategoryModel;
use Anomaly\VideosModule\Series\SeriesModel;

class AnomalyModuleVideosCreateVideosFields extends Migration
{

    /**
     * The addon fields.
     *
     * @var array
     */
    protected $fields = [
        'title' => 'anomaly.field_type.text',
        'name' => 'anomaly.field_type.text',
        'description' => 'anomaly.field_type.textarea',
        'slug' => [
            'type' => 'anomaly.field_type.slug',
            'config' => [
                'type' => '-',
                'slugify' => 'title'
            ]
        ],
        'poster' => 'anomaly.field_type.file',
        'series' => [
            'type' => 'anomaly.field_type.relationship',
            'config' => [
                'title_name' => 'title',
                'related' => SeriesModel::class
            ]
        ],
        'categories' => [
            'type' => 'anomaly.field_type.multiple',
            'config' => [
                'title_name' => 'name',
                'related' => CategoryModel::class
            ]
        ]

    ];

}

AnomalyModuleVideosCreateVideosStream

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;

class AnomalyModuleVideosCreateVideosStream extends Migration
{

    /**
     * The stream definition.
     *
     * @var array
     */
    protected $stream = [
        'slug' => 'videos',
        'translatable' => true,
        'title_column' => 'title'
    ];

    /**
     * The stream assignments.
     *
     * @var array
     */
    protected $assignments = [
        'poster',
        'title' => [
            'required' => true,
            'translatable' => true,
        ],
        'slug' => [
            'unique' => true,
            'required' => true,
        ],
        'description' => [
            'required' => true,
            'translatable' => true,
        ],
    ];

}

AnomalyModuleVideosCreateSeriesStream

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;

class AnomalyModuleVideosCreateSeriesStream extends Migration
{

    /**
     * The stream definition.
     *
     * @var array
     */
    protected $stream = [
        'slug' => 'series',
        'translatable' => true,
        'title_column' => true
    ];

    /**
     * The stream assignments.
     *
     * @var array
     */
    protected $assignments = [
        'title' => [
            'required' => true,
            'translatable' => true,
        ],
        'slug' => [
            'unique' => true,
            'required' => true,
        ],
        'description' => [
            'required' => true,
            'translatable' => true,
        ],
    ];

}

AnomalyModuleVideosCreateCategoriesStream

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;

class AnomalyModuleVideosCreateCategoriesStream extends Migration
{

    /**
     * The stream definition.
     *
     * @var array
     */
    protected $stream = [
        'slug' => 'categories',
        'translatable' => true
    ];

    /**
     * The stream assignments.
     *
     * @var array
     */
    protected $assignments = [
        'title' => [
            'required' => true,
            'translatable' => true,
        ],
        'slug' => [
            'unique' => true,
            'required' => true,
        ],
        'description' => [
            'required' => true,
            'translatable' => true,
        ],
    ];

}

ryanthompson - 9 months ago

Gotta assign that categories field @endder and the rest will be done for ya

ryanthompson - 9 months ago

Think of the fields as a pool of available fields. Assigning them actually puts them to use for a table and the pivots. Columns are handled when assigning the field not when creating the field.

endder - 9 months ago

@ryanthompson Arr i get it now. so I assign 'categories' to videos stream migration and.....YES! that has created the table for me. Wicked! In the video you create the 'series' field, but you didn't assign it to anything. Is that for a later lesson or is it being used in some way?

Thanks for the quick reply.

ryanthompson - 9 months ago

Ya I really need to redo the videos I have - it was a mad sprint to get into it and I learned a lot! Time to revisit and make some new ones ^_^

sachinraee - 3 months ago

Hello sir how do i assign 'categories' to videos stream migration ?