Questions tagged [relationships]

Relationships refer to mappings between elements of one set to another set, such as one-to-one, one-to-many, many-to-many.

Relationships can be implicit or explicit depending upon the data model.

Types of relationships

References

832 questions
7
votes
4 answers

The correct way of storing document reference in one-to-one relationship in MongoDB

I have two MongoDB collections user and customer which are in one-to-one relationship. I'm new to MongoDB and I'm trying to insert documents manually although I have Mongoose installed. I'm not sure which is the correct way of storing document…
Sithu
  • 4,752
  • 9
  • 64
  • 110
6
votes
2 answers

EF Code First: Many-to-many and one-to-many

This is probably just because my knowledge with the EF Code First fluent API is lacking, but I'm stumped. I want to model the following: A Groups collection with Id and Name A Users collection with Id and Name Each user is assigned to exactly one…
6
votes
0 answers

MongoDB/ Mongoose many to many relationship - user, project and role

Our project has following requirements- User can be part of multiple projects A project can have multiple users. User can be either Owner or Admin or Viewer of a project. Obviously there can only one Owner of a project. There can be multiple Admin…
6
votes
3 answers

How to model a mutual friendship in Rails

I know this question has been asked before on Stack Overflow, but the answers aren't doing it for me in ways I can explain. My general approach was inspired by this tutorial. What I'm trying to do, is create a really simple model for friending users…
Captain Stack
  • 3,572
  • 5
  • 31
  • 56
6
votes
3 answers

Querying Relationship Existence using multiple MySQL database connections in Laravel 5.2

I am dealing with the following situation: I have two models, an Employee with id and name fields and a Telephone with id, employee_id and flag fields. There is also an one-to-many relationship between these two models, that is an employee may have…
ira
  • 5,569
  • 6
  • 30
  • 41
6
votes
1 answer

django-import-export: How to import data with foreign keys that doesn't have the keys, but the names?

I am trying to set up django-import-export to handle my data which is stored in spreadsheets. The spreadsheets don't contain foreign keys as IDs, but rather they contain the (also unique) names of the correlating object. Within my database I will…
6
votes
0 answers

SqlAlchemy 'after_insert' event on relationship?

I have a setup which look something like this class Topic(db.Model): __tablename__ = 'topic' id = db.Column(db.Integer, primary_key=True) parent = db.relationship( 'Topic', secondary='parent_child_relation', …
Andrew
  • 1,890
  • 3
  • 16
  • 35
6
votes
1 answer

What's the difference between embedsMany and hasMany in Strongloop loopback

At first sight they seem to do the same thing: define a one-to-many relation So why would you choose one or another?
Ernie
  • 972
  • 1
  • 10
  • 23
6
votes
1 answer

Core Data relationships (swift)

I'm building an app that requires a core data relationship as such: entityA <<---> entityB (e.g. any given entityA can hold many entityB objects) I have two tableviews with entityA list items in which I want to be able to store entityB objects in…
Leighton
  • 6,559
  • 7
  • 21
  • 28
6
votes
2 answers

Laravel/Ardent - on save(), error: Relationship method must return an object of type Illuminate

I'm having some trouble getting my Laravel relationships to work out. In my application, there is a one-to-many relationship between users and ideas. (A user may have multiple ideas.) I'm using Ardent. Here's my User model: use…
clone45
  • 8,952
  • 6
  • 35
  • 43
6
votes
3 answers

Laravel belongsTo only returns the id and not the entire object

I was under the impression that when I use a belongsTo relationship in my model, it will return the object but I seem to only get the id. Is this supposed to happen and what is the benefit of this? This is my code: From my Photo model public…
Robert Lee
  • 95
  • 1
  • 6
6
votes
1 answer

Limiting relationships in Laravel

I have a model Post which has a hasMany('Comments') relationship. I would like to fetch all Posts with the Comments relationship, but only the latest one comment for each Post. And because there are thousands of posts with thousands of comments…
Yasen Slavov
  • 787
  • 4
  • 16
6
votes
2 answers

How can I delete an entry from a HABTM join table in rails?

Through many iterations of testing, I just noticed that my join table that represents a HABTM relationship between two models isn't removing entries when instances of these models get deleted. Do I need to do something special when removing an…
6
votes
2 answers

Symfony2 Doctrine get random product from a category

I have the following database scheme: table 'products' id category_id and of course a category table, just with an id. The data look something like that: Products -------------------- | id | category_id | -------------------- | 0 | 1 | |…
Dennis Schnelle
  • 63
  • 1
  • 1
  • 3
6
votes
3 answers

Create a One-to-Optional-One constraint in SQL Server

i have a "main table", call it Customers: CREATE TABLE Customers ( CustomerID int PRIMARY KEY NOT NULL, FirstName nvarchar(50), LastName nvarchar(50) ) And i have a "satellite table", call it…
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
1 2
3
55 56