Implement hasOne() relationship ID binding.#61
Merged
DarkSide666 merged 6 commits intodevelopfrom Jul 21, 2016
Merged
Conversation
Applied fixes from StyleCI
Applied fixes from StyleCI
| if ($this->their_field) { | ||
| return $m->loadBy($this->their_field, $this->owner[$this->our_field]); | ||
| return $m->tryLoadBy($this->their_field, $this->owner[$this->our_field]) | ||
| ->addHook('afterSave', function ($m) { |
Member
There was a problem hiding this comment.
Do we need afterSave hook here even if referenced model can be loaded? This is good if we allow to change id of model, but ... do we allow that?
Member
Author
There was a problem hiding this comment.
That is a very good point. I'm not sure which one is better.
Member
There was a problem hiding this comment.
I don't think agile/data supports changing model id. Can we do:
$m->load(1);
$m['id'] = 2;
$m->save(); // update table set id=2 where id=1 ??? do this work or will create insert instead?
Member
Author
There was a problem hiding this comment.
OK, i think i want to keep as-is for the following pattern:
$user->ref('contact_id')->load(123)->save();
which allows to easily update to a different record.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When populating model that contains hasOne() relation, sometimes you want to also populate the related entity. This should nicely place the ID of a new record into the main table:
This should also save $m['address_id'];