|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On January 11 2017 18:55 Acrofales wrote:Show nested quote +On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... Looks like you created a deadlock situation. Change the restrictions on your DB, or accept that there will be undeletable entries. Your only other option is a hack where you add a C called "tobedeleted" or something, and change A to belong to that first, then cascade your delete.
Yeah, figured as much. I'm now trying to change the structure to accommodate my needs.
|
On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B ***has one or more A***
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... FTFY.
So, each C belongs to a single B. It's not an m to n relationship, at least I hope so (for your sake) and each B can have one or more Cs. Each A has exactly one B.
What if we merge A and B into AB:
If the C has exactly one A and that A is the one that the B belongs, you can have a 1 to n relationship:
AB: has relationship to C
C: has relationship to AB
How does this sound?
|
On January 11 2017 20:57 Djagulingu wrote:Show nested quote +On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B ***has one or more A***
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... FTFY. So, each C belongs to a single B. It's not an m to n relationship, at least I hope so (for your sake) and each B can have one or more Cs. Each A has exactly one B. What if we merge A and B into AB: If the C has exactly one A and that A is the one that the B belongs, you can have a 1 to n relationship: AB: has relationship to C C: has relationship to AB How does this sound?
If life were so simple I also have D and E, which belong to C
|
On January 11 2017 21:49 Manit0u wrote:Show nested quote +On January 11 2017 20:57 Djagulingu wrote:On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B ***has one or more A***
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... FTFY. So, each C belongs to a single B. It's not an m to n relationship, at least I hope so (for your sake) and each B can have one or more Cs. Each A has exactly one B. What if we merge A and B into AB: If the C has exactly one A and that A is the one that the B belongs, you can have a 1 to n relationship: AB: has relationship to C C: has relationship to AB How does this sound? If life were so simple  I also have D and E, which belong to C 
AB: has relationship to C
C: has relationship to AB has one or more D has one or more E
D: belongs to C
E: belongs to C
Unless there is another dependency between AB, C, D or E (or C has more than one As), you can just cascade your deletes into:
delete AB: -> delete the associated C
delete C: -> delete the associated D -> delete the associated E
delete D: nothing
delete E: nothing
|
Would I bei legally safe if I murdered the person that created CSS like that?
@media (...) { .someclass > .col-md-3 { width: 50% } } (Standard bootstrap)
|
On January 12 2017 16:54 Morfildur wrote:Would I bei legally safe if I murdered the person that created CSS like that? @media (...) { .someclass > .col-md-3 { width: 50% } } (Standard bootstrap) How much experience does this guy have?
|
|
why bluetooth sucks so much
I have 4 devices (2 android, 1 windows phone, 1 arduino) that has bluetooth. Not any two of them are able to connect each other :/ testing an android app that uses bluetooth
|
Weird. My bluetooth devices are a bit finicky, but once I figure out the settings I can always connect, and the connection is quite stable once set up.
|
On January 11 2017 23:33 Djagulingu wrote:Show nested quote +On January 11 2017 21:49 Manit0u wrote:On January 11 2017 20:57 Djagulingu wrote:On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B ***has one or more A***
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... FTFY. So, each C belongs to a single B. It's not an m to n relationship, at least I hope so (for your sake) and each B can have one or more Cs. Each A has exactly one B. What if we merge A and B into AB: If the C has exactly one A and that A is the one that the B belongs, you can have a 1 to n relationship: AB: has relationship to C C: has relationship to AB How does this sound? If life were so simple  I also have D and E, which belong to C  AB: has relationship to C C: has relationship to AB has one or more D has one or more E D: belongs to C E: belongs to C Unless there is another dependency between AB, C, D or E (or C has more than one As), you can just cascade your deletes into: delete AB: -> delete the associated C delete C: -> delete the associated D -> delete the associated E delete D: nothing delete E: nothing
Solved the problem by doing "on delete: set null" without changing anything in the db
|
On January 13 2017 01:40 Manit0u wrote:Show nested quote +On January 11 2017 23:33 Djagulingu wrote:On January 11 2017 21:49 Manit0u wrote:On January 11 2017 20:57 Djagulingu wrote:On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B ***has one or more A***
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... FTFY. So, each C belongs to a single B. It's not an m to n relationship, at least I hope so (for your sake) and each B can have one or more Cs. Each A has exactly one B. What if we merge A and B into AB: If the C has exactly one A and that A is the one that the B belongs, you can have a 1 to n relationship: AB: has relationship to C C: has relationship to AB How does this sound? If life were so simple  I also have D and E, which belong to C  AB: has relationship to C C: has relationship to AB has one or more D has one or more E D: belongs to C E: belongs to C Unless there is another dependency between AB, C, D or E (or C has more than one As), you can just cascade your deletes into: delete AB: -> delete the associated C delete C: -> delete the associated D -> delete the associated E delete D: nothing delete E: nothing Solved the problem by doing "on delete: set null" without changing anything in the db Of course, soft deleting is always a solution
|
I wanna share my 2 cents of experience about deletion just to maybe add value to the thread 
I never saw things getting really deleted in business oriented apps, dunno what kind of app you are working on though, it maybe a requirement.
in those apps db records all had a disabled flag instead of deletion, which makes querying cumbersome because you have to add disabled=false everywhere 
reason is all data somehow sometime becomes useful and removing is not worth the space or performance you would gain.
plus oop+orm makes it little easier, which entry point to your object graph will be deleted and how it should cascade to the connected entities. it can also handle logical interactions between entities, while not relying on database features, ie cascading or triggers.
oop+orm is not fancy though I imagine it is not liked outside of enterprise environment.
|
On January 13 2017 16:06 Djagulingu wrote:Show nested quote +On January 13 2017 01:40 Manit0u wrote:On January 11 2017 23:33 Djagulingu wrote:On January 11 2017 21:49 Manit0u wrote:On January 11 2017 20:57 Djagulingu wrote:On January 11 2017 18:46 Manit0u wrote:I have a bit of a problem with the DB: A: has one B belongs to C
B: belongs to A has many C
C: belongs to B ***has one or more A***
How do I set my cascades properly so that when I delete A all of B and C are also removed? Right now I'm getting an error that C can't be deleted because it's still referenced by A... FTFY. So, each C belongs to a single B. It's not an m to n relationship, at least I hope so (for your sake) and each B can have one or more Cs. Each A has exactly one B. What if we merge A and B into AB: If the C has exactly one A and that A is the one that the B belongs, you can have a 1 to n relationship: AB: has relationship to C C: has relationship to AB How does this sound? If life were so simple  I also have D and E, which belong to C  AB: has relationship to C C: has relationship to AB has one or more D has one or more E D: belongs to C E: belongs to C Unless there is another dependency between AB, C, D or E (or C has more than one As), you can just cascade your deletes into: delete AB: -> delete the associated C delete C: -> delete the associated D -> delete the associated E delete D: nothing delete E: nothing Solved the problem by doing "on delete: set null" without changing anything in the db Of course, soft deleting is always a solution 
No, no. It still hard-deletes everything. It just sets c_id to null in A while deleting C, thus avoiding the foreign key reference error and everything works just fine (deleting A now deletes B and all C).
On January 13 2017 17:56 mantequilla wrote:I wanna share my 2 cents of experience about deletion just to maybe add value to the thread  I never saw things getting really deleted in business oriented apps, dunno what kind of app you are working on though, it maybe a requirement. in those apps db records all had a disabled flag instead of deletion, which makes querying cumbersome because you have to add disabled=false everywhere  reason is all data somehow sometime becomes useful and removing is not worth the space or performance you would gain. plus oop+orm makes it little easier, which entry point to your object graph will be deleted and how it should cascade to the connected entities. it can also handle logical interactions between entities, while not relying on database features, ie cascading or triggers. oop+orm is not fancy though I imagine it is not liked outside of enterprise environment.
I'm using OOP+ORM (Rails). No soft-deletable on my models yet since it's not a requirement at the moment (might become a requirement later on and then I'll add it). I also didn't set any cascades in the DB because that would disable the ORM callbacks and I don't want that.
|
need help debugging a java problem my understanding is failing me somewhere
At class level I have:
public static int card1Spent; private static Label card1Label = new Label(card1Spent + "/X (1)", skin); private static TextButton card1Button = new TextButton("add point", skin);
(some of this stuff is from libgdx but it shouldn't matter
inside my constructor I have
card1Spent=1 card1Button.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { card1Spent++; card1Label.setText(card1Label.getText().toString()); } });
changelistener is a libgdx thing. it works like you think it would
so when I run my program I have a button that says "add point" and a label that shows "0/X (1)" I don't know why it shows 0/X instead of 1/X
And when I click the button, it stays at 0. It never looks at the updated value, it only looks at the original declaration.
If I make the changelistener:
card1Button.addListener(new ChangeListener() { @Override public void changed(ChangeEvent event, Actor actor) { card1Spent++; card1Label.setText(Integer.toString(card1Spent)); } });
then it originally shows my button and 0/X (1) for the label but then if I press the button it shows "2" for the label, then "3" if i press it again etc etc
so wtf?
It's like when I do "card1Label.setText(card1Label.getText().toString());", it doesn't even see the original variable as ever having been a variable. Is this a bug?
|
public static int card1Spent;
YEUCH. We taught you better than that!
|
Well what's the reason I am not supposed to do this again? Because I do want there to be only one of them and I do want to be able to access it from other classes (geesh I don't want to write a thousand getters).
I guess I can make everything non static, but then none of my GUI can be static either. changes my whole design a lot
|
On January 14 2017 04:32 travis wrote: Well what's the reason I am not supposed to do this again? Because I do want there to be only one of them and I do want to be able to access it from other classes (geesh I don't want to write a thousand getters).
I guess I can make everything non static, but then none of my GUI can be static either. changes my whole design a lot
Your IDE will write getters and setters for you for a reason.
|
On January 14 2017 04:32 travis wrote: Well what's the reason I am not supposed to do this again? Because I do want there to be only one of them and I do want to be able to access it from other classes (geesh I don't want to write a thousand getters).
I guess I can make everything non static, but then none of my GUI can be static either. changes my whole design a lot You will be hurting very bad if you continue with the static fields some day. Perhaps its better to experience this yourself because then you will understand for the rest of your life. Either that or you just trust in the judgement and experience of virtually every somewhat skilled programmer out there.
But to answer your question: Your label shows a "0" for card1Spent because thats the value of card1Spent at the moment you initialize your label. Just because you change the value of your variable later doesnt mean your label will automatically update. You have two solutions: Initialize your variable card1Spent to the correct value before initializing your label or update the label after initializing your variable.
|
If something can be modified, better think twice about making it static. And then think again. Repeat until you don't want to make it static anymore.
|
alright im taking all the advice, my design has been changed
in an unrelated thought, it seems really stupid that java can't cast int to string, I have to use Integer.toString() or some other method, and yet I can simply say that (the string = the int + ""). I'd love to have that one explained to me.
|
|
|
|