luyadev / luya

LUYA is a scalable web framework and content management system with the goal to please developers, clients and users alike.
https://luya.io
MIT License
812 stars 207 forks source link

Plugin CheckboxRelationActiveQuery not selected by default when updating #1794

Closed JohnnyMcWeed closed 6 years ago

JohnnyMcWeed commented 6 years ago

What steps will reproduce the problem?

What is the expected result?

What do you get instead? (A Screenshot can help us a lot!)

Database: Items are saved as expected.

nadar commented 6 years ago

@JohnnyMcWeed If you create a new item with the RELATIONS-BUTTON the item won't be selected, this is an expected behavior. So i assume its not a bug.

JohnnyMcWeed commented 6 years ago

I've got a service model where I added related services.

class Service extends NgRestModel
{
...
'isRelatedTo' => [
    'class' => CheckboxRelationActiveQuery::class,
    'query' => $this->getIsRelatedTo(),
    'labelField' => ['title']
]
...
public function getIsRelatedTo() {
    return $this->hasMany(Service::class, ['id' => 'relation_service_id'])->viaTable('service_is_related_to', ['service_id' => 'id']);
}
}

This works quite well so when adding new elements it saves everything as expected. The problem comes if I'd like to change something later. When opening the service, the related services are not selected anymore. So the next time the service is saved, all related services get removed if I don't remember to select them again each time..

luya-bot commented 6 years ago

Issue moved to https://github.com/luyadev/luya-module-admin/issues/145