谁能帮我解决这个问题吗?
我使用 Typescript 和 mongoose v5.7.6 创建一个 API,该 API 管理用户和车辆,以便车辆具有用户 ID,并且用户具有车辆 ID 列表(mongoose 填充用法)。
我的问题是删除车辆,因为我需要在用户的车辆列表中删除它(级联效应)。我正在使用车辆模型的findByIdAndDelete方法,并为findOneAndDelete创建了预中间件作为文档(https://mongoosejs.com/docs/api/model.html#model_Model.findByIdAndDelete)。
这个findByIdAndDelete方法成功触发了findOneAndDelete中间件,但是如何让正在删除的文档获取其属性作为用户ID呢?
如果我使用删除中间件,我可以访问this元素,但是使用findOneAndDelete中间件,这与 Typescript 上的文档不匹配。
我怎么解决这个问题?
我使用的是 PostGres 10、Python 3.9 和 Django 3.2。我已经建立了这个模型以及伴随的多对多关系......
class Account(models.Model):
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
...
crypto_currencies = models.ManyToManyField(CryptoCurrency)
Run Code Online (Sandbox Code Playgroud)
生成并运行 Django 迁移后,创建了下表...
\d cbapp_account_crypto_currencies;
Table "public.cbapp_account_crypto_currencies"
Column | Type | Modifiers
-------------------+---------+------------------------------------------------------------------------------
id | integer | not null default nextval('cbapp_account_crypto_currencies_id_seq'::regclass)
account_id | uuid | not null
cryptocurrency_id | uuid | not null
Indexes:
"cbapp_account_crypto_currencies_pkey" PRIMARY KEY, btree (id)
"cbapp_account_crypto_cur_account_id_cryptocurrenc_38c41c43_uniq" UNIQUE CONSTRAINT, btree (account_id, cryptocurrency_id)
"cbapp_account_crypto_currencies_account_id_611c9b45" btree (account_id)
"cbapp_account_crypto_currencies_cryptocurrency_id_685fb811" btree (cryptocurrency_id)
Foreign-key constraints:
"cbapp_account_crypto_account_id_611c9b45_fk_cbapp_acc" FOREIGN KEY (account_id) REFERENCES cbapp_account(id) DEFERRABLE INITIALLY DEFERRED …Run Code Online (Sandbox Code Playgroud) 我有一个问题,我正在尝试解决该问题,并使用下面的代码重现了该问题。
我遇到的问题是,我可以从主菜单项获取指定的命令,但是当级联菜单中包含相同的命令时,它似乎不会执行。
我不确定这是否与我的要求有关,我需要渲染按钮网格并为每个按钮附加一个上下文菜单。这是我设计的一些代码来演示这个问题:
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
self.title('Tkinter Validation Demo')
self.create_widgets()
@staticmethod
def print_bg_color(button, button_id):
colour = button.cget('bg')
print(f'Button {button_id} colour is {colour}')
@staticmethod
def _context_menu(event: tk.Event = None, menu: tk.Menu = None):
menu.tk_popup(event.x_root, event.y_root)
def create_widgets(self):
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']
for i in range(0, 7):
button = tk.Button(master=self, bg=colors[i], width=10, height=10)
button.grid(row=0, column=i)
context_menu = tk.Menu(button, tearoff=False)
# Add print option to main menu
context_menu.add_command(label="Print colour",
command=lambda btn=button, button_id=i: …Run Code Online (Sandbox Code Playgroud) 我正在尝试删除父母,但我一直收到外键违规.如果我将Cascade.ALL放在父级中,它也会删除子级.它现在正是我想要的.
我有我的父类:Docteur
//bi-directional many-to-one association to Patient
@OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}, orphanRemoval=false, mappedBy="docteur")
private List patients;
我的孩子是:耐心
我把它
@ManyToOne()
private Docteur docteur;
但在我的情况下,患者的胆量只有一个Docteur.
在我的经理类中.我尝试了许多不起作用的东西
这是我的最新版本
Clinique clinique = read(clinique_ID);
Docteur docteur = entityManager.createNamedQuery("getDocteur", Docteur.class).setParameter("clinique_ID", clinique_ID).setParameter("docteur_ID", docteur_ID).getSingleResult();
clinique.getDocteurs().remove(docteur);
entityManager.merge(clinique);
entityManager.persist(clinique);
这是我得到的错误:
无法删除或更新父行:外键约束失败(jerabi_asteriskdb/Patient,CONSTRAINT FK340C82E5A10F077EFOREIGN KEY(docteur_DOCTEUR_ID)REFERENCES Docteur(DOCTEUR_ID))
我有一个Friends与以下列调用的关系,
User1ID
User2ID
Since
Run Code Online (Sandbox Code Playgroud)
User1ID并且User2ID是关系中的一组主键.它们也是引用表Users的外键.现在我想添加一个ON CASCADE DELETE,这样当删除表Users中的用户时,也会删除表中相应的行Friends.但是,MS SQL Server不允许我添加该约束.
有关如何修改表格的任何想法,以完成该任务?
我有以下映射:
@Entity
@Table(name = "Prequalifications")
public class Prequalification implements Serializable
{
...
@ManyToMany
@JoinTable(name = "Partnerships", joinColumns = @JoinColumn(name = "prequalification_id", referencedColumnName = "id"), inverseJoinColumns = @JoinColumn(name = "company_id", referencedColumnName = "id"))
private Set<Company> companies;
...
}
Run Code Online (Sandbox Code Playgroud)
在@ManyToMany+ @JoinTable映射关系中,是不是隐含的关联(链接)实体(这里Partnerships)被自动持久化,删除等等,即使
默认情况下,关系具有空级联集
?以上引用来自"Pro JPA 2,Mike Keith".
执行
em.merge(prequalification);
Run Code Online (Sandbox Code Playgroud)
在上述实体上确实保留了相关的伙伴关系而没有指定任何级联类型.
我是正确,这隐含的级联有被执行?在我看的任何地方都没有提到......
我将android应用程序移植到了BB10.在应用程序中,如果键盘同时打开,如果显示吐司,它将隐藏在BB10键盘后面,用户无法看到吐司消息.在Android应用程序中它工作得很好只有问题面在BB10中.
我已经阅读了很多关于级联和多对多关联的主题,但我无法找到我的特定问题的答案.
我在UserProfiles和Roles之间有多对多的关系.当我删除UserProfile时,我希望数据库删除连接表(userprofile2role)中的关联记录,因此使用实际的SQL"ON DELETE CASCADE"操作.这可能吗?无论我尝试什么,Hibernate总是创建UserProfile表而不指定ON DELETE行为.
UserProfile映射:
@Entity
public class UserProfile {
private Long id;
private Set<Role> roles;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
public final Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
// Note: CascadeType.ALL doesn't work for many-to-many relationships
@ManyToMany (fetch = FetchType.EAGER)
public Set<Role> getRoles() {
return roles;
}
public void setRoles(Set<Role> roles) {
this.roles = roles;
}
}
Run Code Online (Sandbox Code Playgroud)
角色映射:
@Entity
public class Role {
private Long id;
private Set<UserProfile> userProfiles = …Run Code Online (Sandbox Code Playgroud) 通过启用pragma foreignkeys ON,我以编程方式在ios中创建了一个.sqlite文件
NSFileManager *theFileManager = [NSFileManager defaultManager];
if ([theFileManager fileExistsAtPath:[self getDatabasePath]] == NO)
{
char *theError;
const char *databasePath = [[self getDatabasePath] UTF8String];
const char *enableForienKey = [@"PRAGMA foreign_keys = ON;" UTF8String];
if (sqlite3_open(databasePath, &mDatabase) == SQLITE_OK)
{
if (sqlite3_exec(mDatabase, enableForienKey, NULL, NULL, &theError)!=SQLITE_OK)
{
DEBUGLOG(kCreateTableError,sqlite3_errmsg(mDatabase));
}
sqlite3_close(mDatabase);
}
else {
DEBUGLOG(KFailedToCreateDBFile);
}
}
Run Code Online (Sandbox Code Playgroud)
Pragma外键正在启用但是,我创建了两个表,如下所示,创建查询包括ON DELETE CASCADE //第一个表创建查询
@"CREATE TABLE IF NOT EXISTS Session (sessionAppID INTEGER PRIMARY KEY NOT NULL , sessionID VARCHAR(255) NOT NULL, userAppID INTEGER, deviceAppID INTEGER …Run Code Online (Sandbox Code Playgroud) 如何在NHibernate中通过代码映射设置级联到all-delete-orphans?
[Flags]
public enum Cascade
{
None = 0,
Persist = 2,
Refresh = 4,
Merge = 8,
Remove = 16,
Detach = 32,
ReAttach = 64,
DeleteOrphans = 128,
All = 256,
}
Run Code Online (Sandbox Code Playgroud)
如何组合All和DeleteOrphans?
cascade ×10
many-to-many ×3
jpa ×2
android ×1
command ×1
django ×1
eclipselink ×1
foreign-keys ×1
hibernate ×1
ios ×1
java ×1
jpa-2.0 ×1
menu ×1
middleware ×1
mongoose ×1
nhibernate ×1
one-to-many ×1
postgresql ×1
python ×1
python-3.x ×1
sql-delete ×1
sql-server ×1
sqlite ×1
tkinter ×1
typescript ×1