Skip to content

Conversation

Pr3d4dor
Copy link
Contributor

@Pr3d4dor Pr3d4dor commented May 20, 2020

This pull request adds the ability to customize pivot table columns (belongsToMany).


Closes #175

Copy link
Collaborator

@jasonmccreary jasonmccreary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good start. But incomplete.

As noted in a previous comment, let's limit this to the custom table name only.

In addition, the MigrationGenerator will also need to be updated to honor any custom table name when generating code for the table name.

$relationship = "";
if (!is_null($class) && $type === 'belongsToMany') {
if (preg_match("/^[A-Z]/", $name)) {
$relationship = sprintf("\$this->%s(%s::class)->using(%s::class)", $type, '\\' . $model->fullyQualifiedNamespace() . '\\' . $relationShipClass, '\\' . $model->fullyQualifiedNamespace() . '\\' . $name);
Copy link
Collaborator

@jasonmccreary jasonmccreary May 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use single quote for all strings.


$relationship = "";
if (!is_null($class) && $type === 'belongsToMany') {
if (preg_match("/^[A-Z]/", $name)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear that this preg_match determines if the developer passed a model reference.

I am open to supporting this. But I feel there are more implications (e.g. generating the pivot model). For now, I think we should focus on the original issue, which was specifying the custom table name.

Said another way, let's assume, for now, that whatever they pass is a custom table name.

@Pr3d4dor
Copy link
Contributor Author

Ok, tomorrow I will update the pull request with the requested changes.

@jasonmccreary
Copy link
Collaborator

@Pr3d4dor, no rush. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ability to customize pivot columns
3 participants