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
9
votes
6 answers

Refactoring nested for loops

I have this situation where I have a parent child relationship between two sets of data. I have a parent document collection and a child document collection. The requirement is that the parents and their corresponding children need to be exported…
sc_ray
  • 7,803
  • 11
  • 63
  • 100
9
votes
2 answers

How to find sqlalchemy remote side object's class or class name without db queries?

Let's have a classes X and Y and relations between them x2y and y2x. From class_mapper(Class).iterate_properties iterator we can get all class's properties. So x2y and y2x are RelationshipProperty and what I hope to get from is a class or a class…
mdob
  • 2,224
  • 3
  • 22
  • 25
9
votes
1 answer

TypeORM relationship: Only IDs instead of whole instances

According to the documentation, in TypeORM a relationship is defined as follows: A user has exactly one profile. import {Entity, PrimaryGeneratedColumn, Column, OneToOne, JoinColumn} from "typeorm"; import {Profile} from…
stoniemahonie
  • 321
  • 1
  • 5
  • 13
9
votes
3 answers

PHP object parent/child recursion

I've got a parent-child OO relationship. Parent obejcts has many child objects and every child object knows about it's parent by reference. The parent can be a child too (basically its a tree). When i do a var_dump() on the root object it says…
Damien
  • 674
  • 5
  • 12
9
votes
1 answer

Laravel - Search relation including null in whereHas

I'm trying to find a way to search the relationship. So, I have one to one relation (User and UserDetails, where some of the user can be without details). So, the question is... how can I search Users by their details, but also Users without details…
9
votes
5 answers

Laravel hasOne through a pivot table

So I have 2 models, User & Profile, the relationship is set up as follows: /** * User belongs to many Profile * * @return \Illuminate\Database\Eloquent\Relations\belongsToMany */ public function profiles() { …
ChrisBratherton
  • 1,540
  • 6
  • 26
  • 63
9
votes
3 answers

Laravel Relationship availability after save()

I'm building a simple timetracking App using Laravel 5 where I have two Laravel models, one called "User" and one called "Week" The relationships are pretty simple: Week.php: public function user() { return…
Skye Ewers
  • 358
  • 1
  • 4
  • 16
9
votes
1 answer

Laravel get model from ID with belongtoMany

I'm building an application using Laravel 4 but have some problems with the pivot tables. there are 3 tables Categories , Products , products_categories (pivot) Category model public function product() { return $this->belongsToMany('Product',…
Oğuz Çiçek
  • 235
  • 1
  • 3
  • 13
9
votes
3 answers

Grails GORM domain association across two datasources

Is it possible to have an association between two domain classes (i.e. belongsTo) if the other domain class uses a different datasource? The two datasources are different database drivers too. I suspect this may not be possible, but I wanted to…
Thomas Farvour
  • 1,103
  • 2
  • 11
  • 24
9
votes
1 answer

Flask SqlAlchemy : TypeError: 'Class' object is not iterable

I'm following the Flask-SQLAlchemy tutorial. I have Flask 0.9, sqlalchemy 0.7.8 and flask-sqlalchemy 0.16 on python 2.6. (and I work with eclipse) (The tuto is here : http://packages.python.org/Flask-SQLAlchemy/models.html) I have 2 classes : a man…
Yace
  • 165
  • 1
  • 3
  • 6
8
votes
3 answers

Java model validation

We are looking for a Java library/system/package which not only does basic validation but also can do relationship validation. We need to be able to express validation criteria which is based on multiple related entities. Most of the validation…
apara
  • 81
  • 1
  • 4
8
votes
3 answers

Core Data multiple relationships to same entity

I've been studying Core Data quite a bit now, and I've now decided it's time to use it in a new project I'm doing. Having never use it in a working project I've just come across a few issues I would like to get the communities feedback on. I'm doing…
Daniel
  • 23,129
  • 12
  • 109
  • 154
8
votes
3 answers

Are joins on an FK faster than joins without an FK?

Say I have two tables, a and b: a { pk as int fk as int ... } b { pk as int ... } I want to join a and b in a query like so: FROM a JOIN b on a.fk = b.pk Which of the following scenarios will be faster? a.fk is set up to be a foreign key on…
8
votes
3 answers

CakePHP Model Relationship with Multiple Foreign Keys

In my CakePHP app I have models for Matches and Teams. Each Match has a home_team_id and an away_team_id, both of which reference a different Team. In my team.php file, I am able to form the relationship for a Team's home matches: var $hasMany =…
Ben
  • 529
  • 1
  • 7
  • 9
8
votes
3 answers

Laravel - reverse polymorphic relationship

I basically have two models (dog and cat) of the same type: pets. The table pets joins all dogs and cats in the database. Now I would like to be able to find a specific pet through the pet id in the PetController. Like so: $pet =…