assignments on a streams getting over-written/removed with new assignment
Created 7 years ago by emergingdzns

I've got a stream that I initially created that had several multiple field type relationships. However, very recently I wanted to add a new multiple relationship field to the stream. I used the artisan command: php artisan make:migration add_subscription_column --addon=custom --fields So the migration file looks like this:

use Anomaly\Streams\Platform\Database\Migration\Migration;
use Edzns\CustomModule\Subscription\SubscriptionModel;

class EdznsModuleCustomAddSubscriptionColumn extends Migration
{
    protected $stream = [
        'slug' => 'people'
    ];

    protected $fields = [
        'subscriptions' => [
            "type" => "anomaly.field_type.multiple",
            "config" => [
                "related"        => SubscriptionModel::class,
                "mode"           => "lookup",
            ]
        ],
    ];
    protected $assignments = [
        'subscriptions'
    ];
}

Then after running the migration, when I do a dd() on the people stream, it shows:

#relationships: array:1 [▼
    0 => "subscriptions"
]

The other relationships are now missing. What the heck happened? Are the field migrations supposed to remove previously set assignments and relationships?

piterden  —  7 years ago

You need to use the imperative style there.

emergingdzns  —  7 years ago

I don't have the slightest clue what that means @piterden . Can you give me an example?

ryanthompson  —  7 years ago

@emergingdzns are you up to date? What command did you use to run the migration? Does your DB reflect what you see in dd? It's lost all it's other field assignments?

emergingdzns  —  7 years ago

I was following your video on the migration stuff. I am on 3.3.3 now and I think this actually came down to an issue with doing a rollback. When I did a rollback, the stream that was referenced by the slug in the fields got wiped out along with all the assignments. I had a backup thankfully. I put that back and then put back the backup of the assignments table and recompiled. I got it all back now thankfully.

ryanthompson  —  7 years ago

In your additive fields - add this property:

protected $delete = false;

That will tell the system to avoid deleting cause the stream is only there for reference.

I usually use traditional styled migrations after initial ones just cause that delete can be a little weird.

emergingdzns  —  7 years ago

Ahh good to know. Thanks!