[Mindfuck] MySQL PHP relating a table to itself (n:m)

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

[Mindfuck] MySQL PHP relating a table to itself (n:m)

Post by Chris »

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? :shock: WTF did I just type?...

Here's a diagram:
Image

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?
Fighting for peace is declaring war on war. If you want peace be peaceful.
Dominion
Posts: 41
Joined: Wed Nov 20, 2013 10:41 pm

Re: [Mindfuck] MySQL PHP relating a table to itself (n:m)

Post by Dominion »

So... basically you want one field to link everything to so you can send user information from one platform to another well possibly having different version running at the same time?
Chris wrote: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? :shock: WTF did I just type?...
Relating everything by something else is confusing. If you're attempting what I think you are (and it's entirely possible I am way of the mark here) have one master database/table/whatever to start from. Maybe something that stores all locations of a clone, and the original location?
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: [Mindfuck] MySQL PHP relating a table to itself (n:m)

Post by Chris »

Thanks!

I have to clone the fields and the records and relations. The relation records will have to be cloned and the match the x and y id pair.


I think a better solution might be to create a new table between app and app versions. This will help me separate the form logic and the saved data. Do refactoring and modulate the code.
Fighting for peace is declaring war on war. If you want peace be peaceful.
User avatar
Chris
Posts: 1580
Joined: Wed Sep 30, 2009 7:22 pm

Re: [Mindfuck] MySQL PHP relating a table to itself (n:m)

Post by Chris »

I've changed the database around a bit to suite better. Fields will have siblings, the current field_relation logic has been renamed to field_trigger, which seems more appropriate for what it does.

Image
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Advanced Help and Support”