one-to-many

Is it possible use nested SUBQUERY in NSPredicate?

你离开我真会死。 提交于 2019-12-10 13:15:15
问题 As you can see I have two one-many relationships. Is it possible to write such a nested SUBQUERY where I want to select all A, where any of the belonging C-s under any of belonging B to A satisfy a certain condition? 回答1: You can nest SUBQUERY in a predicate. But it seems that a single SUBQUERY is sufficient here (if ds is a to-one relationship from C to D ), for example [NSPredicate predicateWithFormat:@"SUBQUERY(bs, $x, ANY $x.cs.ds.name = %@).@count > 0", name]; 来源: https://stackoverflow

Converting a many-to-many relationship to one-to-many in PostgreSQL

前提是你 提交于 2019-12-10 13:04:40
问题 I have a many-to-many between foo and bar modeled as a table foo_bar with foo_id and bar_id . I'd now like to model this as a one-to-many (which my data allows). I've added a foo_id column to bar but now I want to migrate my data. So, I want to UPDATE bar SET foo_id = f where id = b; where each f and b pair are coming from SELECT foo_id AS f, bar_id AS b FROM foo_bar; Is it possible to do this in SQL (and specifically PostgreSQL 9.0)? I know how to do sub-SELECTs in UPDATEs when there's only

Oracle - With a one to many relationship, select distinct rows based on a min value

孤街醉人 提交于 2019-12-10 12:12:58
问题 This question is the same as In one to many relationship, return distinct rows based on MIN value with the exception that I'd like to see what the answer looks like in other dialects, particularly in Oracle. Reposting from the original description: Let's say a patient makes many visits. I want to write a query that returns distinct patient rows based on their earliest visit. For example, consider the following rows. patients ------------- id name 1 Bob 2 Jim 3 Mary visits ------------- id

Database: `One to One` vs `One to Many`

こ雲淡風輕ζ 提交于 2019-12-10 11:57:06
问题 Note: This is not an inventory controlling system. I am just trying to map which medication given to which patient. I am not considering how many medication packets etc. Just a single medication event I am having a sudden confusion with database relationships, even after working with them for years. Below is my situation. I have a table called patient where it will hold the information of patients. I have another table called medication where it will hold the medicines prescribed for patient

Terminal mongo to one-to-many basic examples

梦想与她 提交于 2019-12-10 10:37:39
问题 There are a lot of "why not JOIN?" questions here, to understand who to use mongodb... But even the guide at model-embedded-one-to-many-relationships-between-documents not show the basic clues... There are to approaches: generate an array that contains the "embedded data" of the join, to produce "on fly" data. (using find() and what more simple algoritm?) use the db.collection.insert to produce "persistent data". So, if I am at mongo terminal, what the simplest way to do that? real-life

how to return a json response based on database relationship using eloquent

寵の児 提交于 2019-12-10 10:01:54
问题 I'm quite new to Laravel. I'm figuring out to work with Eloquent. Let's say I have 2 tables: categories and products. These two table have a one-to-many relationship. 1 category can have many products. I would like to return a JSON response which consists of an array of categories where each category has an array of products. It should look like this: [ {"name":"Category 1", "products": [ {"name":"Product 1","price":"2.50"}, {"name":"Product 2","price":"2.50"} ] }, {"name":"Category 2",

model self-dependency (one-to-many field) implementation

断了今生、忘了曾经 提交于 2019-12-10 01:25:19
问题 I would like to implement a model with self-dependency. Say instance People_A may depend on People_B and People_C. I first implement this model with many to many key. class People(models.Model): dependency = models. ManyToManyField ('self', blank=True, null=True) But the result is that if People_A depend on People_B will result in People_B depend also on People_A. That’s something I don’t want to have. Then I implement it with foreign key. class People(models.Model): dependency = models

How to query datastore when using ReferenceProperty?

家住魔仙堡 提交于 2019-12-09 20:51:32
问题 I am trying to understand the 1-to-many relationships in datastore; but I fail to understand how query and update the record of a user when the model includes ReferenceProperty . Say I have this model: class User(db.Model): userEmail = db.StringProperty() userScore = db.IntegerProperty(default=0) class Comment(db.Model): user = db.ReferenceProperty(User, collection_name="comments") comment = db.StringProperty() class Venue(db.Model): user = db.ReferenceProperty(User, collection_name="venues")

make a One to Many Relation in django

拜拜、爱过 提交于 2019-12-09 20:46:54
问题 I am trying to make a one-to-many relation in django. In my model I have a class Person and a class Group and the relation I want to make is that one Group can have N people inside, and a group cann't exist without at least one person inside In a MER diagram it would be like(imagine these are entities and relations) |group|1====<>-----N|person| 回答1: As Arthur states, this is documented quite well in the Django documentation. It is in fact quite easy: from django.db import models class Person

Hibernate - One to many relationship and orphanRemoval cascade

五迷三道 提交于 2019-12-09 11:39:50
问题 I have a basic one to many relation parent / child like in the chapter 21 of Hibernate references book. The cascade is only from child to parent (persist cascade only because I don't want to delete the parent if I delete a child). When I add a child to the parent and I save the child, I have a TransientObjectException... @Entity public class Parent implements Serializable { @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; @OneToMany(mappedBy = "parent", orphanRemoval =