How to delete a tree node and its childs records from a table (without cascade delete)?
By : Bubbatron11
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further Since you don't want to "alter the table structure", you are down to a recursive query anyway (or a function doing the work recursively). Because adding a FK constraint would qualify as "altering the table structure". Without these restrictions the most elegant solution would be to fix the NULL values you mentioned and add a NOT NULL constraint to the column. Then add the FK constraint with ON DELETE CASCADE as mentioned in the comments, first by @lc. code :
WITH RECURSIVE x AS (
SELECT ad_tree_id, node_id
FROM ad_treenodemm
WHERE (ad_tree_id, node_id) = (1,5) -- enter dead node walking here
UNION ALL
SELECT a.ad_tree_id, a.node_id
FROM x
JOIN ad_treenodemm a ON a.parent_id = x.node_id
)
DELETE FROM ad_treenodemm a
USING x
WHERE (a.ad_tree_id, a.node_id) = (x.ad_tree_id, x.node_id)
|
c#, entity framwork: how is the best way to update/delete childs?
By : Benji Walker
Date : March 29 2020, 07:55 AM
wish of those help In this particular case I think that the best way is to use a trigger to delete de childs.
|
How to delete all entities connected to a entity connected through Key property in appengine
By : mirozake
Date : March 29 2020, 07:55 AM
will help you The best way to do it is to define a pre_delete_hook. This is a function that runs before an entity is deleted. Let this function itself delete any Comments that refer to this post. You can also let it remove the key value from UserDetails as well. The code will be something like this: code :
class Post(ndb.Model):
...
@classmethod
def _pre_delete_hook(cls, key):
comments = Comment.query(Comment.post==key).fetch(keys_only=True)
ndb.delete_multi(comments)
details = UserDetail.query(UserDetail.posts.IN([key])).fetch()
for detail in details:
detail.posts.remove(key)
ndb.put_multi(details)
|
Is there a way to 'get' all connected entities and their attributes connected to a specific instance of an entity?
By : user3024961
Date : March 29 2020, 07:55 AM
Hope this helps In general in Graql we can make ambiguous queries by providing less constraints in the query, or changing a constraint to a more relaxed one. In your case, I believe you want to ask a question specifically about an entity instance, described by this pattern: $t isa technology, has version "v9.5";. You want to find the entities it is connected to via a relation. You then wish to find all of the attributes of those connected entities, but without specifying all of the types of attribute those entities could own according to the schema. code :
match
$t isa technology, has version "v9.5";
$r($t, $e);
get $e;
match
$t isa technology, has version "v9.5";
$r($t, $e);
$e isa entity;
get $e;
match
$t isa technology, has version "v9.5";
$r($t, $e);
$e isa entity, has attribute $a;
get $e, $a;
match
$t1 isa technology, has version "v9.5";
$e1 isa entity, has attribute $a;
$r1($t1, $e1);
$t2 isa technology, has version "v9.6";
$e2 isa entity, has attribute $e;
$r2($t2, $x2);
get $a;
|
JPA Hibernate remove child object of entity, connected with dual PK triggers SQL update instead of delete?
By : Peter
Date : March 29 2020, 07:55 AM
may help you . I have the following table structure: , There are some mistakes in your mapping. code :
@OneToMany(fetch = FetchType.LAZY, orphanRemoval = true)
@JoinColumns({
@JoinColumn(name = "botId", referencedColumnName = "botId"),
@JoinColumn(name = "version", referencedColumnName = "version")
})
private Set<BotEnvironments> environments = new LinkedHashSet<>();
@Entity
@Table(name = "chat_bot")
public class Bot {
@Id
private String id;
@OneToMany(mappedBy = "bot", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<BotVersion> versions = new LinkedHashSet<>();
}
@Entity
@Table(name = "chat_bot_version")
@IdClass(BotVersionPK.class)
public class BotVersion {
@Id
private String botId;
@Id
private int version;
@ManyToOne
@JoinColumn(name = "botId", insertable=false, updatable=false)
private Bot bot;
@Type(type = "text")
private String json;
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, mappedBy = "botVersion")
private Set<BotEnvironments> environments = new LinkedHashSet<>();
}
@Entity
@Table(name = "chat_bot_environments")
@IdClass(BotEnvironmentsPK.class)
public class BotEnvironments {
@Id
private String botId;
@Id
private int version;
@Id
private String environmentCode;
@ManyToOne
@JoinColumns({
@JoinColumn(name = "botId", referencedColumnName = "botId", insertable=false, updatable=false),
@JoinColumn(name = "version", referencedColumnName = "version", insertable=false, updatable=false)
})
private BotVersion botVersion;
}
@Test
public void test() {
// given
BotEnvironments botEnvironments = new BotEnvironments("bid", 1, "env");
BotEnvironments botEnvironments1 = new BotEnvironments("bid", 1, "env1");
BotVersion botVersion = new BotVersion("bid", 1, "json", Set.of(botEnvironments, botEnvironments1));
Bot bot = new Bot("bid", Set.of(botVersion));
botRepository.save(bot);
// when
Bot savedBot = botRepository.findAll().get(0);
savedBot.getVersions().iterator().next().getEnvironments().remove(savedBot.getVersions().iterator().next().getEnvironments().iterator().next());
botRepository.save(savedBot);
// then
assertEquals(1, botEnvironmentsRepository.findAll().size());
}
|