Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model has-one-through relations #14511

Merged
merged 9 commits into from
Nov 4, 2019

Conversation

zsilbi
Copy link
Member

@zsilbi zsilbi commented Nov 4, 2019

Hello!

  • Type: new feature

In raising this pull request, I confirm the following:

  • I have read and understood the Contributing Guidelines
  • I have checked that another pull request for this purpose does not exist
  • I wrote some tests for this PR
  • I have updated the relevant CHANGELOG
  • I have created a PR for the documentation about this change

Small description of change:

This is very similar to hasManyToMany, but it can only use one intermediate row.
The related record is either ModelInterface, or null.

This is kind of an antipattern, but it can be useful when you have to work with a poorly designed database structure that can't be altered.

Thanks,
zsilbi

@niden niden added 4.0 documentation Documentation required new feature request Planned Feature or New Feature Request labels Nov 4, 2019
@codecov
Copy link

codecov bot commented Nov 4, 2019

Codecov Report

Merging #14511 into 4.0.x will decrease coverage by 0.04%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##            4.0.x   #14511      +/-   ##
==========================================
- Coverage   67.74%    67.7%   -0.05%     
==========================================
  Files         482      482              
  Lines      111424   111754     +330     
==========================================
+ Hits        75483    75659     +176     
- Misses      35941    36095     +154

@niden niden merged commit ecdbb93 into phalcon:4.0.x Nov 4, 2019
@niden
Copy link
Member

niden commented Nov 4, 2019

Thank you @zsilbi

@niden niden removed the documentation Documentation required label Dec 1, 2019
@scrnjakovic
Copy link
Contributor

@zsilbi Could you explain why it's anti-pattern? I genuinely want to know. I thought it's perfectly normal to design database that way if you want to have an optional relationship and normalized database, i.e.

document
document_id (PK)
...

document_approved_by
document_id (PK)
user_id (FK)

user
user_id (PK)

instead of

document
document_id (PK)
approved_by (FK) nullable

Thanks and also thanks for PR :)

@zsilbi zsilbi deleted the model-has-one-through-relation branch February 18, 2020 16:44
@zsilbi
Copy link
Member Author

zsilbi commented Feb 18, 2020

@zsilbi Could you explain why it's anti-pattern?

What I think I really meant there, that performance wise there can be better alternatives to this.
But I also started to use it in some distinct cases, and I also see the beauty in your example. 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature request Planned Feature or New Feature Request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants