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

[5.1] Eloquent relations improvements #8491

Closed
wants to merge 3 commits into from

Conversation

rkgrep
Copy link

@rkgrep rkgrep commented Apr 20, 2015

Work is still in progress, however I want to know if you would accept such changes

The patch applies two fixes to eloquent belonging relations:

  1. Drop relation on change of relative field
$child = new Child();
$parent_id = $child->parent->id; //Assume parent_id is 888. Parent is still there and loaded

$child->parent_id = 999;
$child->save();

$parent_id = $child->parent->id; //We still get old parent loaded previosly - which is a bug

The patch forces such relations to be cleared on model update.

onDirty method added to provide internal saving event without Event package.

  1. Inject parent to children on resolving having relations (fixes Odd Relationship Behaviours #8085)
$child = $parent->child; //HasOne, HasMany, MorphOne, etc. relation

$parent_id = $child->parent->id; //New query which can cause n+1 problem

$childrent = $parent->children()->with('parent'); // Works but nonscence - unnescessary extra query.

In this patch parent model automatically injected into children in one-to-many relations.

Next - I plan to fix #5414, #6368 and implement some more relations improvements.

@rkgrep rkgrep changed the title Patch belongstomany [5.1] Eloquent relations improvements Apr 20, 2015
@rkgrep rkgrep deleted the patch-belongstomany branch May 25, 2015 11:14
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