Skip to main content

Questions tagged [relationship]

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

Filter by
Sorted by
Tagged with
436 votes
4 answers
554k views

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's user avatar
  • 23.9k
386 votes
2 answers
651k views

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 ...
user avatar
164 votes
8 answers
345k views

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'; ...
Lic's user avatar
  • 1,917
116 votes
9 answers
126k views

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's user avatar
  • 2,188
113 votes
6 answers
145k views

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 ...
SuperManSL's user avatar
  • 1,306
109 votes
14 answers
102k views

How to delete/create databases in Neo4j?

Is it possible to create/delete different databases in the graph database Neo4j like in MySQL? Or, at least, how to delete all nodes and relationships of an existing graph to get a clean setup for ...
rmv's user avatar
  • 3,225
102 votes
7 answers
133k views

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/...
Huei Tan's user avatar
  • 2,265
100 votes
4 answers
161k views

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's user avatar
  • 35.2k
97 votes
4 answers
165k views

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 ...
borisdiakur's user avatar
  • 11.5k
93 votes
6 answers
120k views

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's user avatar
  • 6,193
79 votes
9 answers
259k views

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's user avatar
78 votes
11 answers
70k views

SQLAlchemy cannot find a class name

Simplified, I have the following class structure (in a single file): Base = declarative_base() class Item(Base): __tablename__ = 'item' id = Column(BigInteger, primary_key=True) # ... ...
Ross's user avatar
  • 46.8k
75 votes
4 answers
81k views

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=...
wanderlust's user avatar
  • 1,916
71 votes
7 answers
58k views

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 this: $model->...
Benubird's user avatar
  • 19.2k
65 votes
3 answers
27k views

Understanding Core Data delete rules on One to Many

I am a little fuzzy about Core Data Relationships deletion rules. So if someone could help me answer a few questions about them. I have Entities A and B. A has a to-Many relationship with B, and B ...
Shamy's user avatar
  • 773
64 votes
2 answers
34k views

anybody tried neo4j vs titan - pros and cons [closed]

Can anybody please provide or point out to a good comparison between Neo4j and Titan? One thing i can see is in terms of scale - Titan is scaleout and requires an underlying scalable datastore like ...
DevD's user avatar
  • 1,221
60 votes
4 answers
30k views

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 ...
Dan's user avatar
  • 703
60 votes
3 answers
121k views

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's user avatar
  • 2,900
59 votes
3 answers
31k views

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 ...
Tobias Gies's user avatar
58 votes
2 answers
46k views

What rel=profile is for?

While doing the HTML for my new template, I stumbled across a new meta tag <link rel="profile" href="http://gmpg.org/xfn/11" /> What's this for? I found it linking to this page, and through ...
Omar Abid's user avatar
  • 16k
51 votes
3 answers
36k views

How do I access the properties of a many-to-many "through" table from a django template?

From the Django documentation... When you're only dealing with simple many-to-many relationships such as mixing and matching pizzas and toppings, a standard ManyToManyField is all you need. However, ...
Alex's user avatar
  • 2,400
49 votes
9 answers
115k views

How to find all the relations between all mysql tables?

How to find all the relations between all MySQL tables? If for example, I want to know the relation of tables in a database of having around 100 tables. Is there anyway to know this?
user3148861's user avatar
42 votes
6 answers
87k views

Laravel relationships in migrations?

I know you can define table relationships fairly easy with $this->belongs_to(), $this->has_many() etc, but what i don't understand is how the relationship table is created; the table that binds ...
qwerty's user avatar
  • 5,246
40 votes
4 answers
25k views

Laravel Polymorphic Relations Has Many Through

I have a Subscriber model // Subscriber Model id user_id subscribable_id subscribable_type public function user() { return $this->belongsTo('App\User'); } public function subscribable() { ...
Edward's user avatar
  • 431
40 votes
2 answers
23k views

Neo4j Bidirectional Relationship

Is there a way to create bidirectional relationship in Neo4j using Cypher? I would like the relationship to be bidirectional rather than making two unidirectional relationships in both directions For ...
sgp's user avatar
  • 1,758
39 votes
7 answers
81k views

Laravel check if relation is empty

I have an object with some relationships and I need to check if these relations are empty or not, I'm trying to check with is_null, isset, != undefined, etc but nothing works, here is the relationship ...
Spialdor's user avatar
  • 1,535
39 votes
1 answer
92k views

Hibernate: Where do insertable = false, updatable = false belong in composite primary key constellations involving foreign keys?

When implementing composite primary keys in Hibernate or other ORMs there are up to three places where to put the insertable = false, updatable = false in composite primary key constellations that use ...
Kawu's user avatar
  • 13.9k
39 votes
3 answers
92k views

Determine Which Objects Reference a Table in SQL Server

I need to rename a table that has many columns and stored procedures that process against that table. How can one get all Items in database that have a relation to a table in such a scenario?
Tavousi's user avatar
  • 15.3k
38 votes
1 answer
29k views

Elasticsearch relationship mappings (one to one and one to many)

In my elastic search server I have one index http://localhost:9200/blog. The (blog) index contains multiple types. e.g.: http://localhost:9200/blog/posts, http://localhost:9200/blog/tags. In the ...
Aruljothi's user avatar
  • 497
33 votes
4 answers
108k views

Laravel whereDoesntHave() - multiple OR conditions

In Laravel 4.2 I have a model called Product with many-to-many relationshis to other models like Country or Category. I want to filter out products that are "incomplete", which means they have no ...
KazikM's user avatar
  • 1,329
33 votes
1 answer
53k views

Get ids array from related laravel model which is having belongsToMany relationship

I have a model Role which belongs to many Users. Class Role { public $fillable = ["name"]; public function users() { return $this->belongsToMany('App/Models/User')->...
sp11's user avatar
  • 333
33 votes
4 answers
25k views

How to define two relationships to the same table in SQLAlchemy

I’ve looked all over the SQLAlchemy tutorial and other similar questions but I seem to be struggling to get this join to work: The scenario: I have a pages table represented by the Page model. Pages ...
richzilla's user avatar
  • 41.4k
33 votes
1 answer
57k views

MySQL - How to insert into table that has many-to-many relationship

I have a table of persons. Each person has a property and many persons may have a certain property. So this is a many-to-many relationship. This is the schema: CREATE TABLE persons ( person_id int(...
Christos Baziotis's user avatar
31 votes
3 answers
36k views

How to view database diagram in a Code First using localdb

I have a Code First project with Entity Framework 5.0.0 using localdb created in Visual Studio 2012 Ultimate. Although I can see my class relations in a Class Diagram, how to see a visual diagram of ...
Xaqron's user avatar
  • 30.6k
30 votes
5 answers
24k views

Add record to a has_and_belongs_to_many relationship

I have two models, users and promotions. The idea is that a promotion can have many users, and a user can have many promotions. class User < ActiveRecord::Base has_and_belongs_to_many :...
Kevin Whitaker's user avatar
29 votes
2 answers
14k views

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'); ...
Javier Pozo's user avatar
29 votes
6 answers
29k views

Laravel merge relationships

Is there a way to merge 2 relationships in laravel? this is the way it's setup now, but Is there a way I could return both merged? public function CompetitionsHome() { return $this->HasMany(...
Kiwi's user avatar
  • 2,743
28 votes
3 answers
45k views

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(...
Matthijn's user avatar
  • 3,224
27 votes
2 answers
10k views

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 ...
Mateus Pinheiro's user avatar
27 votes
2 answers
10k views

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 ...
preyz's user avatar
  • 3,129
27 votes
2 answers
46k views

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 ...
The Pjot's user avatar
  • 1,850
26 votes
3 answers
39k views

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 $...
Joe's user avatar
  • 15.8k
26 votes
5 answers
25k views

MySQL Foreign Key On Delete

I am trying to figure out relationships and deletion options. I have two tables, User and UserStaff, with a 1:n relationship from User to UserStaff (a user can have multiple staff members). When my ...
Baub's user avatar
  • 5,024
26 votes
1 answer
8k views

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's user avatar
  • 14.7k
23 votes
7 answers
58k views

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(...
adam78's user avatar
  • 9,978
23 votes
3 answers
9k views

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 ...
Ankit's user avatar
  • 6,882
23 votes
1 answer
4k views

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 ...
Thomas's user avatar
  • 2,446
22 votes
10 answers
73k views

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:...
Keith's user avatar
  • 26.4k
22 votes
6 answers
78k views

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'...
Jonathan de M.'s user avatar
22 votes
3 answers
55k views

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 ...
user2276094's user avatar

1
2 3 4 5
130