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
422
votes
4 answers

How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

Can anyone explain how to implement one-to-one, one-to-many and many-to-many relationships while designing tables with some examples?
arsenal
  • 23,366
  • 85
  • 225
  • 331
372
votes
2 answers

Laravel - Eloquent "Has", "With", "WhereHas" - What do they mean?

I've found the concept and meaning behind these methods to be a little confusing, is it possible for somebody to explain to me what the difference between has and with is, in the context of an example (if possible)?
user4898812
158
votes
8 answers

Laravel where on relationship object

I'm developing a web API with Laravel 5.0 but I'm not sure about a specific query I'm trying to build. My classes are as follows: class Event extends Model { protected $table = 'events'; public $timestamps = false; public function…
Lic
  • 1,757
  • 3
  • 14
  • 16
115
votes
9 answers

Implementation difference between Aggregation and Composition in Java

I'm aware of the conceptual differences between Aggregation and Composition. Can someone tell me the implementation difference in Java between them with examples?
Rajath
  • 2,178
  • 6
  • 32
  • 38
113
votes
6 answers

Laravel save / update many to many relationship

Can anyone help me on how to save many to many relationship? I have tasks, user can have many tasks and task can have many users (many to many), What I want to achieve is that in update form admin can assign multiple users to specific task. This is…
SuperManSL
  • 1,306
  • 2
  • 12
  • 17
101
votes
7 answers

Delete all nodes and relationships in neo4j 1.8

I know this question is asked by many people already for my research, here's some questions asked before How to delete all relationships in neo4j graph? https://groups.google.com/forum/#!topic/neo4j/lgIaESPgUgE But after all, still can't solve our…
Huei Tan
  • 2,237
  • 3
  • 23
  • 34
94
votes
3 answers

Laravel Eloquent - Attach vs Sync

What is the difference between attach() and sync() in Laravel 4's Eloquent ORM? I've tried to look around but couldn't find anything!
Kousha
  • 32,871
  • 51
  • 172
  • 296
93
votes
4 answers

How to use an include with attributes with sequelize?

Any idea how to use an include with attributes (when you need to include only specific fields of the included table) with sequelize? Currently I have this (but it doesn't work as expected): var attributes = ['id', 'name', 'bar.version',…
borisdiakur
  • 10,387
  • 7
  • 68
  • 100
89
votes
6 answers

UML relationships - dashed line vs solid line

What is the difference between these 2 relationships? Edit: Also if you could provide a simple code example illustrating the difference, that would be really helpful!
NPS
  • 6,003
  • 11
  • 53
  • 90
77
votes
9 answers

Meaning of "n:m" and "1:n" in database design

In database design what do n:m and 1:n mean? Does it have anything to do with keys or relationships?
Abdullah Khan
  • 2,384
  • 2
  • 22
  • 32
69
votes
4 answers

Inserting new records with one-to-many relationship in sqlalchemy

I'm following the flask-sqlalchemy tutorial on declaring models regarding one-to-many relationship. The example code is as follows: class Person(db.Model): id = db.Column(db.Integer, primary_key=True) name = db.Column(db.String(50)) …
wanderlust
  • 1,826
  • 1
  • 21
  • 25
68
votes
7 answers

How do I reload a relation collection in laravel?

In Laravel, after using attach() or detach() to add or remove something from a relation, the collection has not changed. So if I have a model whose relation contains [1, 2], after…
Benubird
  • 18,551
  • 27
  • 90
  • 141
60
votes
4 answers

Ruby on rails - Reference the same model twice?

Is it possible to set up a double relationship in activerecord models via the generate scaffold command? For example, if I had a User model and a PrivateMessage model, the private_messages table would need to keep track of both the sender and…
Dan
  • 703
  • 1
  • 7
  • 11
58
votes
3 answers

Doctrine 2 - Disallow null value on foreign keys of ManyToOne relationships

I have a ManyToOne relationship in one of my entities, like so: class License { // ... /** * Customer who owns the license * * @var \ISE\LicenseManagerBundle\Entity\Customer * @ORM\ManyToOne(targetEntity="Customer",…
Tobias Gies
  • 724
  • 1
  • 6
  • 15
58
votes
3 answers

Laravel: Get pivot data for specific many to many relation

My User model has many Target and vice versa. Now I've got a given User and given Target and I want to access pivot data from their relation. The pivot column is called type How can I achieve this?
Bernd Strehl
  • 2,852
  • 4
  • 24
  • 43
1
2 3
99 100