[Mindfuck] MySQL PHP relating a table to itself (n:m)
Posted: Tue Dec 03, 2013 2:26 pm
A small intro, I'm making a form builder on top of Yii Framework. All the fields get stored in the database, the rules are related to the fields, the saved data is related to an app version and the data field.
I'm being mindfucked when relating a data row to itself, so when it is cloned, it is related to the original row as well as cloning all the original relations?
WTF did I just type?...
Here's a diagram:

WTF?
platform_version_form_field relate to eachother in more instances.
Instance 1.
When an option in a select list has been selected, the system checks if there is a relation to another field, if the condition matches, it does the verb, this is currently an enum of "enable", "disable", "display" and "hide". (e.g.: on select change -> if has relation & condition ? show related field : hide related field )
Instance 2.
All fields are related to forms which are related to platform versions, the other way round: platfrom_version has many platform_version_form has many platform_version_form_field. When creating a new platform_version, all the relations have to be able to be cloned. A new relation is also made to the field it was based on. So platform_version_form_field has one ? or has many ? platform_version_form_field?
Instance 3.
When a customer creates a new version of an App. The data has to be able to be cloned from a previous app based on a different platform_version.
Example: Customer has an app on iOS 6 and are ready to fill in the details about the new iOS 7 version. When they create a new iOS 7 app_version app_version_record is cloned from the iOS 6 version related through the platform_version_form_field, all the data is cloned to fields which have a correct relation.
I'm mindfucked. Someone explain what I'm doing?
I'm being mindfucked when relating a data row to itself, so when it is cloned, it is related to the original row as well as cloning all the original relations?
Here's a diagram:

WTF?
platform_version_form_field relate to eachother in more instances.
Instance 1.
When an option in a select list has been selected, the system checks if there is a relation to another field, if the condition matches, it does the verb, this is currently an enum of "enable", "disable", "display" and "hide". (e.g.: on select change -> if has relation & condition ? show related field : hide related field )
Instance 2.
All fields are related to forms which are related to platform versions, the other way round: platfrom_version has many platform_version_form has many platform_version_form_field. When creating a new platform_version, all the relations have to be able to be cloned. A new relation is also made to the field it was based on. So platform_version_form_field has one ? or has many ? platform_version_form_field?
Instance 3.
When a customer creates a new version of an App. The data has to be able to be cloned from a previous app based on a different platform_version.
Example: Customer has an app on iOS 6 and are ready to fill in the details about the new iOS 7 version. When they create a new iOS 7 app_version app_version_record is cloned from the iOS 6 version related through the platform_version_form_field, all the data is cloned to fields which have a correct relation.
I'm mindfucked. Someone explain what I'm doing?
