Questions in this tag typically involve the association that a set of data has with other set(s) of data.
Questions tagged [relationship]
5577 questions
28
votes
3 answers
Can't get Laravel associate to work
I'm not quite sure if I understand the associate method in Laravel. I understand the idea, but I can't seem to get it to work.
With this (distilled) code:
class User
{
public function customer()
{
return $this->hasOne('Customer');
…

Matthijn
- 3,126
- 9
- 46
- 69
27
votes
2 answers
SQLAlchemy: How to order query results (order_by) on a relationship's field?
Models
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, ForeignKey
from sqlalchemy import Integer
from sqlalchemy import Unicode
from sqlalchemy import TIMESTAMP
from sqlalchemy.orm import…

The Pjot
- 1,801
- 1
- 12
- 20
27
votes
2 answers
HABTM Polymorphic Relationship
I'm pretty new to Rails, and i'm trying to do a polymorphic HABTM relationship. The problem is that I have three models that I want to relate.
The first one is the Event model and then are two kind of attendees: Users and Contacts.
What I want to do…

Mateus Pinheiro
- 870
- 2
- 12
- 20
27
votes
2 answers
Many To Many relationships in Laravel: belongsToMany() vs. hasManyThrough()
What is the difference between using belongsToMany() or hasManyThrough() when defining a Many To Many relationship in Laravel?
Example:
User
Account
Account_User
So, User has a many to many relation to Account via the Account_User table. On top of…

preyz
- 3,029
- 5
- 29
- 36
26
votes
3 answers
Eloquent relations - attach (but don't save) to Has Many
I have the following relations set up:
class Page {
public function comments() {
return $this->hasMany('Comment');
}
}
class Comment {
public function page() {
return $this->belongsTo('Page');
}
}
Pretty bog…

Joe
- 15,669
- 4
- 48
- 83
26
votes
1 answer
What inverse_of does mean in mongoid?
What inverse_of does mean in mongoid associations? What I can get by using it instead of just association without it?

freemanoid
- 14,592
- 6
- 54
- 77
23
votes
7 answers
Adding Relations to Laravel Factory Model
I'm trying to add a relation to a factory model to do some database seeding as follows - note I'm trying to add 2 posts to each user
public function run()
{
factory(App\User::class, 50)->create()->each(function($u) {
…

adam78
- 9,668
- 24
- 96
- 207
23
votes
3 answers
ER-Diagram: Ternary Relationship - How to read properly?
Im not quite sure how to read ternary relationships within a ER-Diagram.
Lets say this is the ternary relationship that is given.
What can I interpret out of that?
It says that you have to put your hand on 2 entity sets and then read it like…

user2276094
- 399
- 1
- 4
- 11
22
votes
10 answers
How to design a movie database?
I'm trying to get my head round this mind boggling stuff they call Database Design without much success, so I'll try to illustrate my problem with an example.
I am using MySQL and here is my question:
Say I want to create a database to hold my DVD…

Keith Donegan
- 26,213
- 34
- 94
- 129
22
votes
1 answer
How can I use ElasticSearch-Rails query dsl to return related relationships
I am new to ElasticSearch, but need to use it to return a list of products. Please do not include answers or links to old answers which reference the deprecated tire gem.
gemfile
ruby '2.2.0'
gem 'rails', '4.0.3'
gem 'elasticsearch-model', '~>…

Thomas
- 2,426
- 3
- 23
- 38
22
votes
6 answers
Eloquent select rows with empty string or null value
I have something like $user->albums()->where('col', NULL), it works fine then I tried to extend it to empty strings with $user->albums()->where('col', NULL)->or_where('col', '') and it's not working.
Also I saw on this post that I could use…

Jonathan de M.
- 9,721
- 8
- 47
- 72
22
votes
3 answers
How to store bidirectional relationships in a RDBMS like MySQL?
Suppose I want to store relationships among the users of my application, similar to Facebook, per se.
That means if A is a friend(or some relation) of B, then B is also a friend of A. To store this relationships I am currently planning to store them…

Ankit
- 6,772
- 11
- 48
- 84
21
votes
2 answers
Laravel: Create morphs() relationship nullable
I want to create a one-to-one polymorphic relation allow null relation.
Example:
Schema::create('ps_assistances', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('assistance_number',…

Javier Pozo
- 385
- 1
- 3
- 11
21
votes
3 answers
Saving CoreData to-many relationships in Swift
I have a one-to-many relationship that looks like so,
I've set up my model classes in a file to match:
import CoreData
import Foundation
class Board: NSManagedObject {
@NSManaged var boardColor: String
@NSManaged var boardCustomBackground:…

Pirijan
- 3,430
- 3
- 19
- 29
20
votes
4 answers
UML association vs. composition and detail level
Actually, make that a couple of amateur UML questions! When creating a UML diagram to model some domain concepts and you come across a domain concept that "holds" some information about another concept, is it better to hold a stamp/reference to that…

Roger2233
- 231
- 1
- 2
- 3