Realm中的关系数据库? [英] Relational database in Realm?

查看:140
本文介绍了Realm中的关系数据库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在iOS Realm DB中创建简单的关系数据库。我如何链接用户ID和那里的Wishlist产品类似于SQL中的关系数据库。例如波纹管图像:

I want to create simple relational database in the iOS Realm DB. How can i link user id and there Wishlist product similar to the relational database in SQL. Example like bellow image :

我知道我可以创建2个单独的Realm模型(表)来存储带有time_stamp的用户id和带有Wishlist的第二个表,其中有每个愿望清单产品或用户ID和愿望清单的用户ID,其中用户有一个愿望清单数组。现在我想要存储多个愿望清单的所有用户。这意味着每次用户进入APP时,我都必须查询现有的每个愿望清单,以查看它是否适用于此特定的愿望清单。问题出在Wishlist表中,它没有任何主键和领域,不允许创建没有主键的模型。

I know i can create 2 separate Realm models (tables) to store user id with time_stamp and in second table for Wishlist where there are user id with each Wishlist products or user id and a Wishlist, where the user has an array of Wishlist. Now i want to store all users with there multiple wishlists. This means that every time the user enters in APP, I have to query every wishlists in existence to see whether its intended for this specific wishlists. The problem is in Wishlist table, it doesn't have any primary key and realm not allowing to create model without primary key.

Realm是否支持外键概念?并且使用复合键是退出复杂的。有没有更有效的方法呢?

Does Realm support foreign key concept ? and use of composite key is quit complicated. Is there a more efficient way to do this?

推荐答案

你可以使用RLMArray,其中RLMArray是Realm中的容器类型定义多对多关系。
如官方Realm文档中提到的目标c检查示例此处
另外通过这个链接可能会有所帮助 RLMArray doc

You can use RLMArray , where RLMArray is the container type in Realm used to define to-many relationships. As mentioned in the official Realm documentation for objective c check example here. Also go through this link it might help RLMArray doc

这篇关于Realm中的关系数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆