Application Logic Vs Data Enforcement

30 views
Skip to first unread message

Gavin Baumanis

unread,
Aug 5, 2016, 7:03:45 AM8/5/16
to Gremlin-users
Hi again everyone,

Firstly,, thanks for your patience with my newbie / dumb-questions of late....

I actually think I might already have an answer for myself with this one - which would in effect - pretty much answer all my previous ones, too.


I have been thinking about my questionnaire problem and started wirth some gremlin code like this;


// The QUESTION to ask and the prescribed answers to choose from
schema
.propertyKey('number').Int().ifNotExists().create()
schema
.propertyKey('answer').Text().ifNotExists().create()
schema
.propertyKey('nextQuestion').Int().ifNotExists().create()
schema
.propertyKey('question').Text().multiple().properties('answer', 'nextQuestion').ifNotExists().create()


My idea was to try and enforce some application logic into my database.


Ask THIS question : question Number 1,
Allow ONLY these 5 possible answers... Have the answer direct you to the next appropriate question (number) based on the answer provided.


The more I thought about it - the more I thought....

APPLICATION logic..... DATA...


Am I just being a little silly, in that I am trying to enforce application logic / rules into my data storage?


What if I did something really "out there" - and had the application deal with it all - and the data - JUST be the data?


I know it was mentioned as a solution to a specific question I asked earlier...

But I've only just thought - that I could / should??? apply that rulle to the entire application?


It would make things pretty simple to conceptualise....

I wouldn't have to worry about enforcing data integrity via the data...

If you only want to show 3 address types in a HTML Select list, code the select list appropriately - in the application.

Just let the database be for data storage only.


Some things make sense of course, like single / multiple cardinality

And within DSE (possibly all gremlin-based solutions) - you can ONLY have meta properties on vertex properties...

But all of these are built into the DB platform and - there are only a few DB "rules" AND they're pretty simple / general and straight-forward.



I think I have just been trying too hard to apply RDBMS logic / recipes to graph - letting go of something that is just innate - is pretty hard....

Dylan Millikin

unread,
Aug 6, 2016, 3:14:25 AM8/6/16
to gremli...@googlegroups.com
Hey Gavin,

I'm not sure I really understand which of these you're trying to accomplish : Are we talking about application logic and routing your user through questions depending on answers, or are we talking about validating the user's answers (checking that an address/email/phone/anything is valid). Or perhaps both, neither? 

Sounds like you're essentially trying to store you question + answer form fields and types in the database so your application can just dynamically generate user forms for each question and then link to the next question depending on the answer. Did I get that right?

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/8540f59d-dcc3-4ca6-8dc1-f9b8a7443cb4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gavin Baumanis

unread,
Aug 6, 2016, 9:40:04 PM8/6/16
to gremli...@googlegroups.com
Hi Dylan,

Yes you have it right.

The Question;
The possible answers for a question 
and the NEXT question that "a" answer leads to - are "prescribed".

I was initially trying to get the decision-tree enforced by the data / data model.

Prior to coming to graphs (and I am JUST starting to use one) I would have said that it all sounds like data : enforce the rules with appropriate foreign keys.
But there are no FKs in a graph.

(apologies if i don't quite have the notation right)
In my visualisation of the graph I think I would have;
Question (0..*) Answer (0..1) Question ...until you reach the end of the prescribes path.


It "seems" ok, albeit very linear, so I just wanted to make sure that I was doing it right?

In this scenario, does it make sense to model the decision tree via the graph?
Or should I "code" the Question to Answer to NextQuestion - paths in the application?

A little broader, is it a good design choice to enforce "logic" via the data model?
Is logic best left for the application code?
Are there any "sensible" design patterns that help with making this choice in the future?

Thanks!
-Gavin.


As always thanks!

Gavin Baumanis

I, for one, like Roman numerals.


--
You received this message because you are subscribed to a topic in the Google Groups "Gremlin-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gremlin-users/FibBkgLcwmY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/CAE0QJeoYf3NaQZcwm9ChBj%2B%2B3iwPr-OTbNZUtbwm4x%2BE_SZ-HA%40mail.gmail.com.

Dylan Millikin

unread,
Aug 7, 2016, 12:25:52 PM8/7/16
to gremli...@googlegroups.com
Ok so you're trying to do two things with the database. Model the application logic and also store the user information (choices). 
It's pretty easy to imagine how the first one would go, but how you would integrate the second part in that existing data model is a little confusing. I'm not sure how you would represent/store a user moving through that logic (maybe by connecting a user to the final leaf you could backtrack up the tree to see all answers/questions). 

Anyways, if you wanted to use the DB to model the application logic, then modeling the decision tree in the graph could be a good way of doing things.
Furthermore the form field types could be set as vertices of their own as they would be reused across multiple questions. So you could imagine : 
(Question) --[weight : 1]--> (FieldType)
And so on with various weights to obtain all form fields. This would allow you to set the proper form elements and do correct validation.

I'm not sure if there are many counter indications for such a DM but I could see it working. The other big question is what type of data mining queries would you want to run against the graph. 
I've found that data modeling with graphs is more about figuring out what queries you will run against the system and then modeling a graph that is optimized for those queries.




Reply all
Reply to author
Forward
0 new messages