Skip to content

[5.6] fix pivot timestamp columns without parent#23917

Merged
taylorotwell merged 1 commit into
laravel:5.6from
browner12:pivot
Apr 18, 2018
Merged

[5.6] fix pivot timestamp columns without parent#23917
taylorotwell merged 1 commit into
laravel:5.6from
browner12:pivot

Conversation

@browner12

Copy link
Copy Markdown
Contributor

The motivation of this PR is to allow Pivot models to be queried and saved just like normal Models.

Previously, when trying to save pivot models, an error would be thrown because no pivotParent existed on the model.

This was due to the getCreatedAtColumn() and getUpdatedAtColumn() methods being called. It erred with "Call to a member function getCreatedAtColumn() on null".

This PR makes sure we first check if the pivotParent property exists. If it does, we continue to use the pivot parent's methods. However, if it doesn't, we fallback to the Models methods.

The tests I've added cover both cases of having a pivotParent and not having one.

- check to see if `pivotParent` exists before getting its timestamp columns.
- if there is no parent, fallback to the parent `Model` methods.
- add tests. 1 for when a parent exists, and 1 for when it doesn't
@taylorotwell taylorotwell merged commit dbc03fa into laravel:5.6 Apr 18, 2018
@browner12 browner12 deleted the pivot branch April 18, 2018 13:21
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.

2 participants