Created
January 18, 2012 15:15
-
-
Save yjeroen/1633460 to your computer and use it in GitHub Desktop.
save relations pattern
This file contains 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
# What I want: | |
# A method that saves related (simple!) models. Simple models only have 1 attribute that requires user input. | |
# Second thing is that I want relations to be toggled with an "active" attribute. | |
# What I have: | |
# If I want a Many Many relation to be 'toggled', i need to make a Has Many relation to the in-between-table Model. | |
# - Public array which holds all related data that needs to be saved. | |
# The array is like this: | |
array | |
( | |
'relationA' => array | |
( | |
'attributeOfA' => array | |
( | |
'0' => 'aaa' | |
'1' => 'bbb' | |
) | |
) | |
'relationB' => array | |
( | |
'attributeOfB' => array | |
( | |
'0' => '111' | |
'1' => '222' | |
) | |
) | |
) | |
# | |
# My pattern: | |
# | |
/* | |
* [for each item in the relation holding array:] | |
* => If relation = Has_Many | |
* => Does this relation have an active toggle? | |
* => do Stuff (update if excists, else create new) | |
* => This relation doesnt have toggles | |
* => do Stuff (delete all, recreate) | |
* => If relation = Many_Many | |
* => do Stuff (delete all, recreate) | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment