-
Notifications
You must be signed in to change notification settings - Fork 101
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
Pivot tables #14
Comments
+1 |
Wouldn't it be a possible solution to inside the Version object append columns for relationships and add an array of IDs / pivot values...? So then to rollback we have the right array to So for instance for the model // Education model adds column in Version object
$pivotRelations = [
"subjects" => [ 2, 12, 42],
] Reverting version would then include looping through the foreach( $pivotRelations as $relation => $items ) {
$this->$relation->sync($items)
} This would also need custom exceptions and handling for when an relation item has been deleted since the old version. The next thing would be storing the relationships. readable diffThe hard thing about this would be making this history readable. that could maybe be solved by complex attributes where you not only just declare what relationships that should be versioned but also the relationships columns that should be used as readable items. So the version data appended could be something like this: // Education model adds column in Version object
$pivotRelations = [
"subjects" => [
"sync" => [2, 12, 42],
"readable" => ["Math", "Biology", "Yoga"]
] The readable array can then act as the source of readable change.. Setting the value in the Education Model: class Education extends Model {
//...
protected $pivotRelationships = [
"subjects" => [ "keyField" => "id", "readableField" => "title"]
]
} Am I getting somewhere or is this just a result of a late night no sleep brain..? |
Right now i cant find a way to handle pivot tables and relations. Is this something you are considering to add in a near future or can give an example on how to do?
Usually when i want to version control stuff in my projects i need a version to include a number of models. Would be nice to be able to specify what models that makes a version. And if any of them is changed we would save a new version for all of them.. including pivot tables.
As an example: If i create a model called "Education", where each row is connected to a number of "Subject" with the help of a pivot table, where each "Subject" have some "Teacher" connected to them connected through a pivot table.
Then i would love the possibility to define that a version would consist of the tables:
[educations,
education_subject,
subjects,
subject_teacher
teachers]
So if any of this tables are changed, create a new version.
Or go by Models like this:
[
'Education' => ['subjects'],
'Subject' => ['teachers']
]
where subjects and teachers is relations in this example.
Any thoughts?
The text was updated successfully, but these errors were encountered: