Skip to content

Instantly share code, notes, and snippets.

@yjeroen
Created January 18, 2012 15:15
Show Gist options
  • Save yjeroen/1633460 to your computer and use it in GitHub Desktop.
Save yjeroen/1633460 to your computer and use it in GitHub Desktop.
save relations pattern
# 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