spatie / mailcoach-support

Questions and support for Mailcoach
https://mailcoach.app
31 stars 2 forks source link

EmailList::tags() ignores model name configuration #198

Closed adamthehutt closed 4 years ago

adamthehutt commented 4 years ago

The mailcoach configuration settings allow for child classes to be used in lieu of the standard Subscriber, EmailList, and Template models. However, the tags() method in the EmailList class fails if different model names have been set.

Currently we have:

public function tags(): HasMany
{
    return $this
        ->hasMany(Tag::class)
        ->orderBy('name');
}

This results in an SQL error when the model is named, say, MailcoachList. The fix should be as simple as:

public function tags(): HasMany
{
    return $this
        ->hasMany(Tag::class, 'email_list_id', 'id')
        ->orderBy('name');
}
adamthehutt commented 4 years ago

It looks like there may be a number of similar issues in other spots. Most everywhere that a relation is defined the code is relying on Laravel conventions to guess the key names, rather than having them explicitly defined. This only works if the Model class base names are the same as the Mailcoach defaults.

riasvdv commented 4 years ago

This should be fixed in the latest version thanks to your PR