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
-1
votes
1 answer

Creating table entry with params hash and associated model(s) params hash

i want to do something like this: user.items << Item.new(params[:item] , :computer => Computer.new(params[:computer] , :laptop => Laptop.new(params[:laptop]))) But this generates an error "wrong number of arguments (2 for 1)"!
-1
votes
2 answers

Get id of intance Ruby on Rails

I am building an ruby app to book accommodations. So I would to put a form_with in the show action for the model Booking. Model Booking is a connection between is User model and Logement Model. To do a Booking a need user_id and logement_id, so I…
-1
votes
1 answer

How can I insert many records from Controller in rails?

I have Classroom model Like: class Classroom < ApplicationRecord has_many :students,dependent: :destroy end I have Student model Like: class Student < ApplicationRecord belongs_to :classroom, optional: true validate…
-1
votes
1 answer

Can't display categories under category type

I have two different models category and category type i just want to display categories under category type but i don't know how. I’m using has_many and belongs_to association where the category has a foreign key 'categorytype_id' I've tried but…
-1
votes
1 answer

How do I set up associations for two different models to belong to one categories model

So I have these 3 models: Coupon, Place, and Category. I want to set up associations such that: Category has both coupons and places associated with it Coupon belongs to several categories Place belongs to several categories. How would I implement…
-1
votes
1 answer

Unpermitted params error while creating records of grand-child records in grand-parent forms

I have three models Book_Room, Invoice, and Bill. Invoice belongs to BookRoom, and has many bills. the error is unpermitted params error for :invoice is thrown when i try to create Book Room after ive clearly asked to accept nested params class…
Prince Abalogu
  • 385
  • 2
  • 4
  • 17
-1
votes
2 answers

Two layers of has_many/belongs_to

enter image description hereI'm writing a to-do list app. Each user can have multiple list categories, and each list category can contain multiple list items: class User < ApplicationRecord has_many :list_categories, dependent: :destroy has_many…
mef27
  • 379
  • 4
  • 15
-1
votes
1 answer

Assocation and Generalization between two classes

Can anyone give me example of class B which inherits from A and there is association between them and what pattern uses such bonds? I am referring to the situation where A is generalization of B and exists association bond between them on UML…
ssukienn
  • 558
  • 6
  • 22
-1
votes
1 answer

Errors in class relationships in c++

I am quite new to the concept of class relationships and wrote a program to test it out. However, it is giving me some errors. There are 5 header files for classes University,Dept,Teacher,Student and Course and a .cpp file involved. I have…
-1
votes
2 answers

Rails - One-direction table association - accessing data issue

I have two models: class Order < ActiveRecord::Base belongs_to :user has_one :order_type end class OrderType < ActiveRecord::Base belongs_to :order end my schema.rb: create_table "order_types", force: :cascade do |t| t.string "ort_name" …
Michal
  • 139
  • 3
  • 14
-1
votes
1 answer

Display content through ActiveRecord_Association_CollectionProxy

I have a Products model with a 'has_many' relationship to Microposts. Likewise, Microposts has a 'belongs_to' relationship to Products. throught this relationship I want to populate a row in table with all the available microposts for that product.…
-1
votes
1 answer

get count of has_many association in rails query

I have a two model. Post and `Comment'. Post has_may comments. Query: I want to get the max count of comments in which post. This should be done by rail query.
Vinay
  • 324
  • 1
  • 3
  • 15
-1
votes
1 answer

Relationship of SQL and NoSQL entities in Symfony

I use symfony on my web page, I want to use both mongodb and mysql in my database model, and i don't know how to link between a table on my sql and a document on mongodb. Example: PERSON -- relation 1--n -- ADDRESS, where PERSON is a table on my…
-1
votes
1 answer

rails Unizillaize constant in Association

I'm trying to find the relations between Surgeon and Appointments. 2.0.0-p195 :001 > surgeon = Surgeon.first Surgeon Load (0.1ms) SELECT "surgeons".* FROM "surgeons" ORDER BY "surgeons"."id" ASC LIMIT 1 => #
Papouche Guinslyzinho
  • 5,277
  • 14
  • 58
  • 101
-1
votes
1 answer

Rails save data association models from single form

I have 3 table User(id,email) Client_Org(id,name) Role(id,user_id,client_org_id,role) role:default "CD" Form add new client organization = form_for(@client_org,remote: true) do |f| .post_errors .form_add_email =f.label :"Name of Client…
chinh
  • 273
  • 1
  • 4
  • 15
1 2 3
57
58