Questions tagged [relationship]

Questions in this tag typically involve the association that a set of data has with other set(s) of data.

5577 questions
13
votes
4 answers

Laravel hasManyThrough equivalent: belongsTo relationship through another model

I've got a model, it belongs to another model, that model belongs to a third model, and I want an eloquent method to relate the first model to the third one. There doesn't appear to be a belongsToThrough (or hasOneThrough) method, though. I've…
BenjaminRH
  • 11,974
  • 7
  • 49
  • 76
13
votes
1 answer

What is local and remote side?

The questions below are related to database table relationships and the abstractions which SQLAlchemy provides for it. What is the difference between remote and local side? If there is remote_side then why not a local_side? In the example given…
Bleeding Fingers
  • 6,993
  • 7
  • 46
  • 74
13
votes
1 answer

Many to many lookups in Django

This is probably insultingly simple and worthy of a Nelson Muntz laugh, but I'm having a real braindead moment tryng to make many to many connections across various model relationships. I have the following models (simplified for your…
Steerpike
  • 17,163
  • 8
  • 39
  • 53
13
votes
2 answers

set null value in a foreign key column?

I have this table CREATE TABLE [dbo].[CityMaster]( [CityID] [int] NOT NULL, [City] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL, [BranchId] [varchar](10) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL CONSTRAINT…
13
votes
8 answers

Programming a one-to-many relationship

So I am surprised that doing a search on google and stackoverflow doesn't return more results. In OO programming (I'm using java), how do you correctly implement a one-to-many relationship? I have a class Customer and class Job. My application is…
MarioDS
  • 12,895
  • 15
  • 65
  • 121
12
votes
1 answer

Core Data add relationship as unique constraint- iOS

I'm developing an application with core data. There are many entities that uses relationships and in many of them they are the primary key. I'm trying to use the unique constraints feature in the xcdatamodel but there is no way to compile the…
Joel Ollé Ripoll
  • 451
  • 1
  • 4
  • 15
12
votes
3 answers

Getting all objects from hasMany relation and paginate

In my Laravel application, I have a category listing page. When the user clicks on a certain subcategory, I'd like to list all the products and use pagination on that result. I'm already listing all the products related to that subcategory, for now,…
Sid
  • 5,693
  • 3
  • 33
  • 50
12
votes
2 answers

Django 1.8 - Intermediary Many-to-Many-Through Relationship - What is the consequence of where 'ManytoManyField' is used?

An example Many-to-Many through relationship in Django: class First(models.Model): seconds = models.ManyToManyField(Second, through='Middle') class Middle(models.Model): first = models.ForeignKey(First) second =…
StringsOnFire
  • 2,726
  • 5
  • 28
  • 50
12
votes
8 answers

Representing parent-child relationships in SharePoint lists

I need to create some functionality in our SharePoint app that populates a list or lists with some simple hierarchical data. Each parent record will represent a "submission" and each child record will be a "submission item." There's a 1-to-n…
Chris Farmer
  • 24,974
  • 34
  • 121
  • 164
12
votes
5 answers

Laravel: how to get average on nested hasMany relationships (hasManyThrough)

I have three tables: products: id|name|description|slug|category_id|... reviews: id|product_id|review_text|name|email|... review_rows id|review_id|criteria|rating the review table stores the review text, writer of the review and has a foreign…
Luuk Van Dongen
  • 2,391
  • 6
  • 26
  • 40
12
votes
2 answers

swift core data fetching relationship

I'm a little bit confused try to fetch relation data from coredata in swift Person Entity contains the name of person and Unique Id. The relation with Books is ONE to Many For example Person Entity: idPerson = 25 - namePerson = John idPerson = 26 -…
Stefano Vet
  • 567
  • 1
  • 7
  • 18
12
votes
2 answers

Relationship fault with core data

(Using swift / Xcode beta 3) I have two entities in my project - a parent entity which has a one-to-many relationship with its children. When adding new objects before saving the context, everything works fine. However, after restarting the app and…
Paweł
  • 1,201
  • 1
  • 14
  • 27
12
votes
4 answers

Laravel - Selecting specific columns on many-to-many relationships

I have two models in my Laravel 4.2 web application, User and Group. A user can be a member of many groups, and a group can have many members. Both models are thus joined with a many-to-many relationship:
cafonso
  • 909
  • 11
  • 18
12
votes
2 answers

Can SQLAlchemy automatically create relationships from a database schema?

Starting from an existing (SQLite) database with foreign keys, can SQLAlchemy automatically build relationships? SQLAlchemy classes are automatically created via __table_args__ = {'autoload': True}. The goal would be to easily access data from…
Eric O. Lebigot
  • 91,433
  • 48
  • 218
  • 260
11
votes
3 answers

SQLAlchemy declarative many-to-many self-join via Association object

I have a table Users and a table Friends which maps users to other users as each user can have many friends. This relation is obviously symmetric: if user A is a friend of user B then user B is also a friend of user A, I only store this relation…
Janny
  • 111
  • 1
  • 1
  • 4