Questions tagged [model-associations]

Models can associate in three main ways: one to many, one to one, and many to many.

This is tagged primarily in Ruby community. Models can associate in three main ways: one to many, one to one, and many to many.

865 questions
2
votes
1 answer

UML association class and OOP languages

I am building a web application with Django, I did the design app with UML2. i read that association class concept does not exist in object oriented programming languages, is that true ?? thank you. class diagram
2
votes
3 answers

Rails Polymorphic Association

I'm having a difficult time grasping polymorphic associations in Rails. I have two models, Group and User. A User needs to belong to a group, but a Group can have_many users AND have_many groups. I need my groups to be like a tree, which I think the…
2
votes
0 answers

CakePHP 3 belongsToMany conditions

I have a problem with declaring conditions for my BTM association - probably missunderstood something. Imagine a few tables - Notes, NotesEntities, Entities (the last one is not an actual table, but can be any table like Products, Customers,…
2
votes
1 answer

UML Class Diagrams - Understanding Which Fields are Necessary and When To Have Public Fields

I'm currently working on a UML class diagram for an application which is supposed to be like 'Duolingo'. I am struggling on how to model a many to many relationship. So, I imagine that you have many users which can take many courses (different…
Ariane
  • 365
  • 1
  • 4
  • 16
2
votes
1 answer

multiple has 1 associations in datamapper

I am not sure if what I want to do is wrong or just my implementation. what I want to do is have multiple "has 1" relationships between a person and addresses my models are class Person include DataMapper::Resource property id,serial …
Grant M
  • 648
  • 10
  • 21
2
votes
3 answers

set validation false on association mongoid

I have two models class Person embeds_one :address end class Address embedded_in :person field :city validates :city, :presence => true end Now when I do person.address = Address.new the validation of address is called. But I don't need…
Sadiksha Gautam
  • 5,032
  • 6
  • 40
  • 71
2
votes
1 answer

How to add foreign key associations in Rails model?

I am setting has_many and belongs_to association in Rails Model: Events(name, identifier, eid) and Users(name, uid)and there is confusion regarding foreign key and primary key. I know what foreign key and primary key means but confused which primary…
2
votes
5 answers

Rails ActiveRecord Association

Okay, so here is my question. I have a 3 different models, People, Roles, Client, and Store. Clients have many Stores and can also have many people. Stores have many people. People have various roles. 1 Person can work at multiple stores, and…
2
votes
1 answer

Querying a Sequelize model to match multiple associations

So I have two Sequelize models with this relationship: models.Note.belongsToMany(models.Topic, { through: 'noteTopicRelation' }); models.Topic.belongsToMany(models.Note, { through: 'noteTopicRelation' }); I can make a successful query to the…
2
votes
1 answer

Method for converting strings into foreign key for a one-to-many association

I have a rails model Region for regions that I have visited. Region has a one-to-many association with a Location model, which contains specific locations I have visited within that region. Each region has a name string column. My routes are set…
Dylan Cox
  • 23
  • 2
2
votes
2 answers

Rails association HABTM

I need some help in creating association for my new rails application. I have two models User and Profession. A user might have many professions and profession might belongs to many users. I can do HABTM association in both the models. User…
2
votes
1 answer

CakePHP 3.x - Link and save associations with 3 models through one model

I am using CakePHP version 3.x. I need to link three models (Trackers, Articles, Mentions) through one Model (TrackersArticlesMentions). Here my relations definition: TrackersTable.php $this->belongsToMany('Mentions', [ 'through' =>…
SamHecquet
  • 1,818
  • 4
  • 19
  • 26
2
votes
2 answers

Rails: How do I map out this has_many, has_many association?

I'm currently working on a game for a student project. I'm spinning in circles engineering the associations. Any guidance from the community would be greatly appreciated. There are 3 models/classes: Games, Characters and Quotes. Game: has_many…
Joel Hoelting
  • 1,862
  • 2
  • 23
  • 45
2
votes
1 answer

Rails 5. Update association with exception handling

I have a one-to-many relationship between the classes P(parent) and C(childs). Table C has a unique composite index {p_id, somerow}. Having 2 objects of class P (p1 and p2), I want to combine them into one, doing this through p2.childs.update_all…
0xDEADBEEF
  • 131
  • 13
2
votes
1 answer

Many to Many association in CakePHP 3.x

I have a question which seems is repeated but it's not: I explain with a small example. I have two table: Students & courses. Each Student can take N courses and each course can be taken by N students. I want to have access the courses by Students…
Malus Jan
  • 1,860
  • 2
  • 22
  • 26