FAQ Database Discussion Community


Rails models with Single Table Inheritance and HABTM

ruby-on-rails,ruby,relationships,single-table-inheritance
I have a project with 2 models, Game and Team. A Game has two Teams, an away team and a home team. There is a set number of Teams(no more get created) and each will belong to many Games. I want to be able to do @game.home_team.name instead of @game.teams.find_by_id(@game.home_team_id).first.name....

Database Model to Represent Families, Households, and Relationships

database,model,relationships
Here's my situation. I am building a database to track relationships between people and households. Typically, everything is tied to a "head of household". I am trying to avoid this as it creates problems when people move (i.e. brother finally gets a job and moves out) or families break up...

What is the shorter verb for “establishing a many-to-many relationship”?

many-to-many,terminology,relationships,relational-algebra
When we establish a one-to-one or many-to-one relationship, we can call it mapping. For example, we map a spouse to his/her spouse or each child to its parent. But what would be the verb singifying an establishment of a many-to-many relationship, underlining that it is not a 1+ to 1...

Core Data properties based upon relationships returning NULL

core-data,nspredicate,nsmanagedobject,nsmanagedobjectcontext,relationships
I have a Core Data data model such as I want to display the Teams.name associated with each Batting object in my UITableViewCell. When I try to access batting.teams.name it returns NULL. My opening view controller has a string passed in then creates a new viewController with NSPredicate based from...

Core Data to-one relationship returns NULL

ios,core-data,nspredicate,nsmanagedobject,relationships
The Batting.team relationship doesn't always save properly and returns null sometimes About 100 'Team' NSManagedObjects are saved and can log their attributes as expected. Then about 15000 'Batting' NSManagedObjects are saved and all attributes log correctly except for the relationship. I want the Batting.team relationship to point to the Team...

Optional relationship in SQL Server — How to implement in SSMS Schema Designer

sql-server,ssms,database-schema,relationships,table-relationships
I have two cases where I would like to set 'optional' relationship inside one table or between two tables. First: I want to set this relation as optional, in other words: there will be categories and subcategories in one table, so subcategory column is only optional. Second: Here I want...

Entity Framework (Code First) One to Many and One to One relations (with two entities). How to?

entity-framework,one-to-many,code-first,one-to-one,relationships
I'm trying to do this with EF Code First: There area two tables: Users and Areas. One User belongs to one required area and one Area can have zero or one User (as administrator). Then: Users *..1 Areas and Users 0..1 Areas The Users class: public class User { public...

SQL Count where relationship Doesn't Exist

sql,relationships
I have a 3 Tables, one of which contains a list of incidents, another a list of users and a final one which contains the relationships between the incidents and users. There can be multiple users of differing types related to the incident (affected user or assigned to user, each...

Symfony2: Disconnect Associations on delete

php,symfony2,doctrine2,relationships,orphan
I have two entities - Background and Action. a Background has many Actions. When I delete a Background I want to keep the Action but null the foreign key. Effectively orphaning the entity in a way that will satisfy constraints. I have read so many articles and questions about cascade={"remove"}...

Can association lines be merged in one line in UML?

uml,software-design,class-diagram,relationships
Is it in accordance with the UML standard to merge a few association lines into one line, like on the attached diagram? ...

What's the difference between embedsMany and hasMany in Strongloop loopback

relationships,loopbackjs
At first sight they seem to do the same thing: define a one-to-many relation So why would you choose one or another?

Best way of protecting the show() method against users accessing other users messages

laravel,laravel-4,routing,models,relationships
Ok, so I have a basic messaging system, I have a relationship set up so I can just call $user->messages to retrieve an array of the users inbox messages. I also have a very simple show method that currently only grabs the message with id passed to the show() function....

How to implement the class - Student relationship in c#? [closed]

c#,class,model-associations,relationships
I want to implement a system, which represents a ClassRoom- Student relationship. I want to impose the constraint that Each ClassRoom can have any number of students, but one student can be at only one ClassRoom. I have created two classes - ClassRoom and Student. I have created a list...

Laravel/Eloquent save validation with parent/child relationships

laravel,eloquent,relationships
I have a parent model which must never exist without at least one associated hasMany relation. I am attempting to write validation for the model to ensure this never happens. public static function boot() { parent::boot(); // reject model with no children if (count($workflow->children) === 0) { throw new RuntimeException("need...

How to GROUP and SUM a pivot table column in Eloquent relationship?

laravel,laravel-4,eloquent,relationships
In Laravel 4; I have model Project and Part, they have a many-to-many relationship with a pivot table project_part. The pivot table has a column count which contains the number of a part ID used on a project, e.g.: id project_id part_id count 24 6 230 3 Here the project_id...

Doctrine one-to-many relationship AND many-to-one

php,symfony2,doctrine2,cascade,relationships
I have two tables. I want to set up a one-to-many relationship, but also a many-to-one relationship. A Page can have one Background - this is the background of the page. A Page can also have many Backgrounds - this is a collection of user-uploaded backgrounds from which one will...

Laravel ORM nested relationships with constraints

laravel-4,nested,relationships
I'm wondering how to perform a nested relationship query with constraints in Laravel 4.1. Here is a reference query which works: $users = User::with("careers.specialty.faculty.university")->get(); As you can see, there are several nested models (with various relation types). I would like to load an optional constraint to one or several models,...