FAQ Database Discussion Community


Three way relationship in Laravel

laravel,eloquent,relationship
having a brain failure with a relationship between three objects, hoping someone can help me out. I have four models: Team, User, ProjectType and Project Team has many User, has many ProjectType User belongs to many Team, has many ProjectType ProjectType belongs to manyUser, belongs to many Team, has many...

Error while Eager loading a Eloquent model with multiple relationship in Laravel 5

php,laravel,eloquent,laravel-5,relationship
My User model have two relationships public function group(){ return $this->belongsTo('App\Group','group_id'); } public function profile() { return $this->hasOne('App\Profile','user_id'); } And Accessing them in Controller like $users = \App\User::with('group','profile')->get(); However, Retriving Profile Model's column give error (Inside a @foreach loop ) @foreach ($users as $user) URL::action('[email protected]',[$user->profile->id]) @foreach ($users as $user) Error...

Retrieving all records through multiple hasMany relationships

php,laravel,laravel-4,relationship
Apologies for the vague title, I'm not quire sure if there's a name for this. I basically have the following relationship between my models in my Laravel 4 application: User -----< Template -----< Job (users haveMany templates, templates haveMany jobs). I want to retrieve all the jobs for a user...

nested relationship Laravel Eloquent query

nested,eloquent,relationship,laravel-5
i've a 3 Models : Pizzerie , Pizze , Ingredients each has his own relationships class Pizzerie extends Model { protected $table = 'pizzerie'; public function pizze() { return $this->hasMany('App\Pizze', 'pizzerie_id'); } } class Pizze extends Model { protected $table = 'pizze'; public function ingredienti() { return $this->belongsToMany('App\Ingredienti', 'pizze_ingredienti'); }...

Creating a Database to a messenger application

mysql,database,table,relationship
I need a Database in MySql that I can save Users and those users could have friends and send messages each other. I have a table Users that I can save the information user, but I don't know how I can save the friends, for example: the user 1 is...

Using Mongoid: Can you use embed_in in multiple documents at the same time?

ruby,mongodb,nosql,mongoid,relationship
I'm getting use to using Mongoid, however I ran into this problem with a situation where I'm trying to use Mongoid. I have a game, the game has teams, the teams have players, and the game has the same players. class Game include Mongoid::Document embeds_many :Players embeds_many :Teams end class...

CakePHP hasOne relationship with different table

php,cakephp,relationship
Each Artikel has exactly one Barcode. For several reasons I want to split the Artikel model and the Barcode model. When I find() something from the artikel table it returns an array which contains the correct barcode section. But when I try to find a barcode, the array's artikel section...

How to model many to many relationships without circles

database,relationship,circle
Note: Because my original question wasn't understood clearly I'm writing it completely new! I have two tables in my database, plus a junction/join table: Recipes: CREATE TABLE Recipes( id INT(11) NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY (id) ) Ingredients: CREATE TABLE Ingredients( id INT(11) NOT NULL AUTO_INCREMENT,...

Rails and Globalize - join translation table of related model in scope

ruby-on-rails,ruby-on-rails-4,relationship,has-many-through,globalize
I want to order some records of a model that has a relation to another model (with translated attributes). Here an example: I have a model Project I have a model Task I have the relation Project has_many Tasks The model Task has attribute name globalized (on task_translations table) Now,...

one to one relationship between classes in java

java,class,relationship
I have to implement following classes in Java SE but I cannot figure out that how can I achieve the one-to-one relationship between ATMCard and Account. I have researched (may be with wrong keywords) but could not find anything. Thank you in advance.. ...

How to create a database relationship between 3 entities (items, their categories and additional fields)?

php,mysql,database,yii,relationship
I'm trying to create a database (using MySQL) for a simple Yii-based website. It will contain a catalog with goods, which are divided into a few categories. The idea is to have a way to add additional fields, specific for each category, and these fields should be fillable for each...

What NoSQL database is good for complex many to many relationships?

mongodb,elasticsearch,neo4j,nosql,relationship
My startup project require complex data structure, which must be ready for geolocation and fulltext search. The information in the database are added by two different types of users, who together build a complex relationship network. For a better understanding of my questions, here is a simple diagram that shows...

Creating new objects with another class

java,class,object,relationship
Okay so I finally finished my assignment and had been testing it by creating objects using right click "New Account" etc, this has all been working fine and from what I can see the Superclasses and Subclasses are all linked correctly, however my work is tested using a test class...

Parse data security and relationships

backbone.js,parse.com,relationship,acl,single-page-application
I'm trying to determine the best approach for the following scenario using Parse and a Backbone front end. I want to build a discussion thread where two or more users, of various roles (ie: member, admin, etc), are able to communicate by posting simple messages which will appear in a...

Users accept the challenge (wordpress data logic)

wordpress,user,relationship
I'm working on a project and do not understand how I can relate data between users and post in wordpress. It is about creating a custom post that challenges users to do "something" and users decide whether to accept the challenge pressing a button (for example). I would understand the...

Neo4J: cypher for relations

neo4j,cypher,relationship
I have a hierarchy in the following format: Application.A <-[:belongs_to {roles:instance}]-Instance.A1-[:depends_on {roles:host}]-> Host.vm1 implying Application A has an instance A1 which is running on Host vm1 with the relation "belongs_to" and "depends_on". Instance.A1-[:depends_on {roles:instance}]-> Database db1 <-[:belongs_to]-Instance.dbNode1-[:depends_on {roles:host}]-> Host.vm2 implying instance A1 of Application A depends on Database db1 that...

Get only the nodes related with bidirectional relatioship

graph,neo4j,cypher,nodes,relationship
I have a neo4j graph where A-[r:LOVE]->B and B-[r:LOVE]->A. I'm trying to get all the nodes with that bidirectional relatioship (some nodes for example C-[r:LOVE]->B but B not love C) and I must get them only 1 time (i don't want to get them duplicated) and ordered by name. I'm...

MySQL Modeling: Relationship normalization & ring issue

mysql,relational-database,primary-key,relationship
I'm building this MySQL model to organize a movie collection. It will manage both movies and series/episodes. Each movie/episode may have one or more audio stream and codecs for audio/video may vary. (don't mind subtitles for now) I'm not an expert, so I'm seeking advice: Ring relationships. Someone told me...

Laravel get model from ID with belongtoMany

php,mysql,laravel,relationship
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', 'products_categories'); } Products Model public function category() { return $this->belongsToMany('Category', 'products_categories'); } products_categories table has product_id and...

In django1.7 , Can one many to many relationship have another many to many relation?

many-to-many,relationship,django-1.7
In Django 1.7 , Can one many to many relationship have another many to many relation ? class KeyValues(models.Model): value=models.IntegerField(max_length=1,blank=True) class Key(models.Model): position=models.IntegerField(max_length=1,default=0,blank=True) keyValues= key=models.ManyToManyField(KeyValues) class FileDetails(models.Model): fileId = models.CharField(max_length = 100,primary_key=True,db_index=True) key=models.ManyToManyField(Key) I wanted to do this type of relation , But I'm getting an error , ERRORS: cloud.Key:...

NoMethodError for relationship between models

ruby-on-rails,ruby,ruby-on-rails-3,relationship
I am setting up a relationship between two of my models. A Patient Model and Worklist Model. My patient can belong to a worklist and a worklist can have many patients. In my form for patients I want to be able to select the worklist from a dropdown menu. I...

Having trouble with mysql relationships?

mysql,many-to-many,relationship,one-to-many
I need two tables, one that shows a one to many relationship using three tables, and another table that shows a many to many relationship. I have managed to do the first 2 with were a query involving just one table, and a one to many involving 2 tables. One...

How to have multiple View Controllers linked to the same Navigation tutorial

swift,uiviewcontroller,uinavigationcontroller,relationship
I have setup a View Controller in Xcode 6 that is embedded in a navigation controller, but I want to setup another View Controller to use that same navigation controller, but when I tried to link the navigation controller to the other View Controller by using the relationship "root view...

Laravel: many-to-many with shared table

php,mysql,laravel,many-to-many,relationship
I have Locations model which hasMany Employees -- similarly Employees belongsTo Locations This is nice and works well, but then I looked at adding PhoneNumbers. Either a Location or an Employee could have a phone number (office numbers versus personal numbers) Logically: Locations hasMany PhoneNumbers (multiple office lines) and Employees...

Neo4j nodes or relationship supports ttl?

neo4j,cypher,relationship,nodes,ttl
I am learning neo4j , i want to know that is there any way that i can create a relationship or a node that will be delete automatically after a certain period of time.

Querying a Pivot table in Laravel 4

mysql,laravel,laravel-4,model,relationship
I have a Email model with the table 'messages' that contains all the message data. I also have a pivot table 'message_users'. How could I return all the messages that a user is associated with? ...

laravel 5 - not sure what kind of relationship I need between two eloquent models

eloquent,laravel-5,relationship
I'm having an issue trying to determine the relationship for the given scenario: Table `appointments` id service_id client_id ... Table `clients` id ... Table `services` id ... What I want is to show all clients for a given service. I initially thought it might be a hasManyThrough IE a service...

Laravel: Delete relationships

php,laravel,controller,relationship
I'm using Laravel 4.2. I have 2 models. I want to make a list of items with a button to delete the relationship. My models: Word { public function posts() { return $this->belongsToMany('Post'); } } Post { public function words() { return $this->hasMany('Word'); } } My desired list for Word...

Rails: find the relationship name of an instance

ruby-on-rails,activerecord,relationship
Assume we have this relationship: class Company < ActiveRecord::Base has_one :company_address, class_name: 'Address', foreign_key: 'company_address_id' has_one :overseas_address, class_name: 'Address', foreign_key: 'overseas_address_id' end If I pry within a new Address instance, is it possible to return :company_address or :overseas_address? Fields are the same, but I want to do different validations. Yes,...

connect nodes with NEXT replation by date

neo4j,cypher,relationship
i have this sample graph: http://console.neo4j.org/?id=mginka and i'm trying to find a Cypher code,that will connect all the hits nodes of each session by the date_time field with [NEXT] relation – hits from different sessions shouldn't be connected.. thanks, Lior...

How do I make sure each post in the Post feed shown in the home page has all its comments displayed under it?

ruby-on-rails,relationship,erb,foreign-key-relationship,instance-variables
I have a Post model, and a Comment model that belongs to Post. I was able to display the Post in the home view corresponding to the home controller and home action and the User/show view. Thus, in the home and user views, the posts are listed in order of...

objective c - set relationship (core data)

ios,objective-c,xcode,core-data,relationship
I'm very new to core data and the project that I'm currently working on involves using core data for local data storage. Below is the structure of my entities. My app functions as follows. When the user first launches the app, there are presented with a login screen. New users...

How I can delete grails domain object with many-to-many relationship?

grails,delete,many-to-many,relationship
class Client { String name String surname String address static hasMany = [departments:Department] } class Department { /*static constraints = { }*/ String depName String location static hasMany = [clients:Client] static belongsTo = Client } def deleteDepartment(){ def values = params.list('departments') def checkedID = new Integer[values.size()] for(int i=0; i<values.size(); i++){...

Laravel: take(1)->count(); what does this mean?

laravel,eloquent,relationship
I am studying the source code of a package, rtConner/laravel-tagging. In this package there is a trait called TaggableTrait. On line 179, in a method called addTag(), there is this line which I don't understand: $previousCount = $this->tagged()->where('tag_slug', '=', $tagSlug)->take(1)->count(); What does this line do? In specific, my problem is...

Spring Data Neo4j 4.0.0: Can't Create Relationship Between Nodes with the Same Label

java,neo4j,nodes,relationship,spring-data-neo4j-4
I'm using Spring Data Neo4j 4.0.0 with Neo4j 2.2.1 and I'm trying to create a relationship between two nodes with the exact same labels. So, I have a NodeEntity class and I have a variable inside with the same Type as the class itself, and annotate it as Relationship. But,...

One To Many Relationship Using Vector Type

java,vector,relationship,one-to-many
I am new to Java programming. I just encountered the new concept of using vector type building a one-to-many relationship. Can you please give me an easy example of using vector type building a one-to-many relationship (including the class, implementation and an example using the class)? Really much appreciated....

How Eloquent work with Relationship?

mysql,laravel,laravel-4,relationship
I'm new to laravel relationship so many apologizes if it's just dumb question. I'm using a pivot table named users_email on the project to get Emails of users. Pivot table contains the foreign key Uid and Email_id. Uid references users table primary key and the same as Email_id. I can...

Relationships in multi tenancy in Laravel Eloquent ORM

php,database,laravel,eloquent,relationship
Once again this is a follow up question to : Multi tenancy in Laravel Eloquent ORM This time around I have questions for using relationships in a multi-tenancy environment for eloquent models. Given a Product model : class Product extends Eloquent { public function accessories() { return $this->belongsToMany('Accessory', 'product_accessory', 'product_id',...

Core Data with SWIFT: How to delete object from Relationship entity?

ios,swift,core-data,relationship
I'm stumped and have not been able to track down any tutorial or document on how best to do this. Problem: I have two entities, Person and Location. Person can have many locations. I have everything setup properly and can add/remove persons from a tableview, no problem. The issue I...

Missing relationships after attaching a database by SQL Server Management Studio

sql-server,relationship
Relationships between entities does not seem to exist after I imported a .mdf file by SQL Server Management Studio and I am sure that this database had many relationships between tables. Does anyone have any idea on what might have happened and how can I solve this problem? ...

Database relationship between products, categories and companies

mysql,database,design,foreign-keys,relationship
I'm creating an EER Diagram with MySQL Workbench. What is the best way to implement a relationship between products, categories and companies tables? I was thinking in this relation, but is this the best way considering I want to allow custommers of a company to manage their own products/categories? Isn't...

how to check if a model is tagged by a specific tag

laravel,laravel-5,relationship,blade
I have model Entity and related model Tag. The later serves as tags, so the relation is serviced by a pivot table I guess it is quite easy, but I am lost. public function tags() { return $this->belongsToMany('App\Models\Tag', 'entity_tags', 'entity_id', 'tag_id'); } Now, in my view I can list all...

grails one to many with additional column

grails,relationship,one-to-many
In my Grails project I need to have a 1:N relationship between two domain classes. So, I've created the following domain class: class Receipt_HealthService { Receipt receipt HealthService healthService int quantity = 1 static constraints = { } } and in Receipt I have the following: @NotNull static hasMany =...

Yii2 how to anchor the value of the relationship in the GridView

php,gridview,relationship
I am beginner. I explain the topic: there is this relationship in the Ticket model: public function getTyp() { return $this->hasOne(Typology::className(), [ 'id' =>'typ_id']); } and in the ticket table there is the typ_id column (it is in relationship with the id of the Typology table). In the view views/ticket/index.php...

Laravel Eloquent - Save/Update Related One-To-Many Relationship Data

php,laravel,eloquent,relationship
I have an entity Set that has many Items in it. So, when updating the sets, the form includes the field to update it's item too. I've done it and it's working well, but I'm not sure if it's the correct and most efficient/elegant way to do it. Here's my...

many to many powerpivot relationship

many-to-many,relationship,powerpivot,powerview
I have 2 data sets which i would like to create relationships for (there is a third i would like to join but the first 2 are priority). They all have a common link that is design_ID. I did have a picture showing what i have tried. but i do...

Defining Ruby on Rails Relationship

ruby-on-rails,ruby,model,relationship
I have the following Models: Users: UserID, FirstName, LastName, State, Gender, Verified, UserTypeID Statuses: StatusID, Message, PostDate, UserID UserTypes UserTypeID, Description, Enabled How would I appropriately associate these relationships? I have the Status one down, but not sure on the UserTypes class User < ActiveRecord::Base has_many :statuses #AssociationToUserTypes end class...

how to assign Post to User through user_id and author_id?

ruby-on-rails,activerecord,relationship
I have a table users. they can post records in different users profiles, so for every post I have user_id (in whose profile a post was written) and autor_id (who wrote the post). Please could you help me - which relations should be to connect posts model with users twice?...

Understanding the Models and Relationships for Creating a Playlist in Rails

ruby-on-rails,model,relationship
I'm using Rails 4.0 with SQLite3. I have four models: User, Album, Song, Playlist. I want users to be able to browse a list of songs and add them to one of their playlists. I can't seem to manipulate these relationships to get the data I want (for example, showing...

Yii2 and table named user_type relation issue with User model of user table

php,mysql,model,relationship,yii2
I have a user table and a User model in yii2 advanced application. The User hasOne relation with UserType model which its table is named user_type and also it hasOne relation with Status model which its table is named status. The two models, i.e. Status and UserType, hasMany relation with...

How does the SANE stack represent parent/child relationships on a single model

ember.js,orm,sails.js,relationship,waterline
How do I represent a parent/child relationship on the same model? An example of this is a model representing a folder. A parent folder can have many children folders. But a child folder can only have one parent folder. Ember.js has the concept of reflexive relations. I would like to...

Laravel where on relationship object

php,laravel,eloquent,where,relationship
I'm developing a web apis with Laravel 5.0 but I've got a doubt about a query. My classes are these: class Event extends Model { // protected $table = 'events'; public $timestamps = false; public function partecipants() { return $this->hasMany('App\Partecipant', 'IDEvent', 'ID'); } public function owner() { return $this->hasOne('App\User', 'ID',...

Building database relationship: a product compatible with another product

ruby-on-rails,database,relationship
I'm building a database with Ruby on Rails which basically store products. One of my main concern is that in the future, I want to be able to know the compatibility which two products. I don't know how to build that in "a Rails way". First I was thinking about...

How to work with cross tables in MySQL?

mysql,sql,relationship
I started using MySQL for a few days and I am using it to create a database for my books. Now, since I have a "many to many" relation between author and books and I've added an associative table to fix the relationship. 1st Table: BOOK book_id as primary key...

Correctly use Eloquent relationships

laravel,orm,eloquent,relationship,foreign-key-relationship
I am developing a Laravel 4 application with 4 database tables: Therapist TherapistType Municipality County I'm using foreign keys to reference the data from other tables. The relationships are the following: A therapist can have one therapist type, municipality and county A therapist type and municipality can belong to many...

How to build relations in rails?

ruby-on-rails,relationship
I am having 3 tables: User which consists of name, email, password, confirm_password, role as fields. Timesheet which consists of date, time, hours_worked as fields. Attachment consists of upload_file field. This upload_file field is used in Timesheet form. Now how can I build relation in all scenarios, for example I...

Find node having two distinct relationship in Cypher

graph,neo4j,cypher,relationship
I am a newbie in Cypher. I am trying to find a query which will returns nodes having more than one relationship to other nodes. Please refer to http://neo4j.com/docs/snapshot/images/cypher-match-graph.svg for the structure. I am trying to find the person who has acted in some movie(s) and also a father. When...

How do I query a table with conditions from related table with Laravel 5

laravel,eloquent,condition,relationship
I have two tables, table users: id, name, etc table videos: id, user_id, etc Model: Video public function user() { return $this->belongsTo('App\Models\User'); } I want to select all videos where it is owned by the user "Max". I have tried thing like the following: $Videos = \App\Models\Video::with('user')->where('user.name','=','Max')->get(); Unknown column 'user.name'...

Is Cascade Delete automatically performed in Entity Framework 1-1 (required) Relationships?

c#,entity-framework,relationship,cascade
Searching about the cascading behavior of Entity Framework, if noticed this answer. On short, the OP is searching for a way to perform cascade delete on 1-0 / 1-1 relationships in Entity Framework, and the best answer contains a snippet on Fluent API applying WillCascadeOnDelete(true); On the DB Context's modelBuilder....

How i create CRUD with relationships in cakephp3

cakephp,relationship,crud,cakephp-3.0
How i do a crud with a relationship between a user and services order? With the code, i can't add users in a team for service order. When cakebake, the controller TeamHasUsersController is created, but the form add don't have any field. The crud has generated with cake bake. ...

Django inheritance, relationship between classes who depends directly/indirectly of same class

django,inheritance,relationship
I don't understand if is possible uses relationship between a model that uses a shared instance, for example i have a Procedure model that uses a class calls Area, and this class (Area) is used inside of Invoice model that needs an instance of ConceptDetail and it needs the Area...

How to add a N:M relationship to my MySQL symptoms and diseases database?

mysql,database,database-design,relational-database,relationship
I am working on a health app and I've created a database (MySQL), which stores symptoms and diseases. There should be a N:M relationship between the symptoms and diseases, so each symptom could have multiple diseases and vice versa. Symptoms should also have common and less common diseases and because...

is it a good practice to assign a class instance to a class attribute in python?

python,class,object,relationship,composition
I'm trying to use class composition in python, and I wonder if it is a good practice to assign a class instance to a class attribute in python. Below are the 2 examples which I have in mind. I appreciate if some experienced programmers could tell me when to use...

Sort model records based on values in related model

ruby-on-rails,ruby,ruby-on-rails-4,relationship
I currently sort member records using in the members model file: default_scope -> { order(:organization_id, :username) } Organizations and members have a 1:many relationship. Instead of ordering on basis of organization_id I would like to order members on basis of the name of the organization, which is a column in...

Sorting a many to many relation with Laravel Eloquent

sorting,laravel,many-to-many,eloquent,relationship
I do have swatches table, a colors table and a swatch_color pivot table. Relations are set as: public function colors() { return $this->belongsToMany('Color'); } public function swatches() { return $this->belongsToMany('Swatch'); } I have no problem to retrieve the swatches with the color relations $swatches = Swatch::with('colors')->get(); return dd($swatches); Colors is...

Neo4j: Relationship direction cypher

neo4j,cypher,relationship
For the cypher - match (m)-[r]-(n) where m.name = 'XYZ' return n.name, type(r), m.name n.name type(r) m.name XYZ belongs_to Ordering Status XYZ runs_on_queue inbound XYZ runs_on_db DBxc In this case, Ordering Status is a business service that "owns" XYZ & the relation is defined as follows: CREATE (XYZ)-[:belongs_to]->(Order) Type(r) only...

How to access an Eloquent relationship using an associative array key

laravel,eloquent,relationship
Say I have Listing model with one-to-many relationship with an Attribute model: class Listing extends Eloquent { public function attrs() { return $this->hasMany('Attribute'); } } class Attribute extends Eloquent { public function listing() { return $this->belongsTo('Listing'); } } Attributes have a code and a value. When I'm handling the Listing,...

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

laravel,orm,eloquent,relational-database,relationship
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)?

Find Cost from Product ID in MS Access

database,ms-access,relationship
I'm trying to create a calculated field for "Total Cost" of an order in MS Access. My tables are related as below: So I want to be able to set Orders: Cost to a calculate field where it takes the associated with each of Items 1,2,3,4 and 5 and sums...