Questions tagged [has-and-belongs-to-many]

A has_many :through association set up a many-to-many connection with another model.

In Ruby on Rails, a has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model.

1372 questions
0
votes
2 answers

Cakephp 3 - save data to belongstomany table

In Cakephp3, I have the following tables: CREATE TABLE `users` ( `id` int(11) NOT NULL, `name` varchar(45) DEFAULT NULL, `created` datetime NOT NULL, `modified` datetime DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; CREATE TABLE…
0
votes
1 answer

RoR lookup HABTM join by multiple ids

I've got 3 tables -- a model QuizResult, a model QuizAnswers and then a jointable for them (quiz_answer_quiz_results): class QuizResult < ActiveRecord::Base has_and_belongs_to_many :quiz_answers, :join_table => :quiz_answer_quiz_results …
grimmwerks
  • 491
  • 1
  • 6
  • 21
0
votes
1 answer

rails 5 belongs_to or has_and_belongs_to_many?

I've been out of the loop for a while and humbly request a refresher. I would like to list all Partners under their respective PartnerCategories in an accordion style toggle
<% @categories.each do |category|…
0
votes
1 answer

Grouping two records and associating the group through a HABTM in ActiveRecord | Rails

I'm working on a Rails 5.2 project that stores and manages guest lists. I have Event and Guest models, and they are associated with a HABTM relationship. This works well, but there is a requirement to be able to optionally store a grouping of two…
0
votes
2 answers

Laravel BelongtoMany relation save extra column with the two model in relation

i try to build form to create invoice and then generate it pdf My Db structure tables: -- invoices contain date | invoice_num | client_id -- articles contain name | description | price -- article_invoice contain invoice_id | article_id |…
Ala Chebil
  • 451
  • 1
  • 8
  • 19
0
votes
1 answer

HABTM and has_many through association issue with multiple database

I am trying to implement the HATBM association between the two models of which one model points to my local database table and other model is pointing to the table of an external database. local model : class Group < ApplicationRecord …
0
votes
1 answer

Sequelize: Create join table attribute with set

I am working with Sequelize 4.38.0 and I have a problem with the belongsToMany association. I defined my tables like this: const Role = db.define('role', { name: {type: Sequelize.STRING, allowNull: false}, standard: {type: Sequelize.BOOLEAN,…
Patcher56
  • 193
  • 2
  • 12
0
votes
1 answer

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation with HABTM association with rails

I have two models enterprise and deal_event with habtm association. This relation works with create and when I do Enterprise.last.deal_events but throws error ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: relation…
0
votes
1 answer

Save data in association table with same entities (belonsToMany) Cakephp 3

I have Campaigns and Actions. Each Campaign can has unlimited actions (even can be repeated). Cakephp documentation say you can save the asociation with actions._ids but I have a problem with this. Each campaign_action has a duration. Then if I use…
0
votes
1 answer

Ordering an array by the count of a related table result

I'm trying the following: I have two models: Pub and User, related by an intermediate table called 'recommended_pubs', where a user set a certain pub as "recommended". The relations are NxN as follows: Pub: /** * @return…
0
votes
1 answer

Save data in association table (belonsToMany) Cakephp 3

I have Campaigns and Actions. Each Campaign can has unlimited actions (even can be repeated). Cakephp documentation say you can save the asociation with actions._ids but I have a problem with this. Each campaign_action has a duration. Then if I use…
0
votes
1 answer

Laravel 5.4 multiple dropdown on belongstomany over two pivots

I'm trying to connect companies that are used by specific user role. A user with a specific role can "work" for multiple companies. A company can "employ" multiple users. I have 5 tables (users, role_user, roles, companies and company_user) Models…
user805528
  • 189
  • 1
  • 5
  • 17
0
votes
1 answer

CakePHP multi-HABTM associations with pagination

For an e-commerce app that I'm building I am using CakePHP. I have created the db and afterwards baked my app with cake bake. My models are all linked up properly as follows: Product hasMany CategoryProduct,ImagesProduct Category hasMany…
0
votes
1 answer

HABTM: can't create a resource

Following this tutorial I'm trying to create a many to many between search and listing models. When everything is set, I can't create a new search. Here's the error I get: irb(main):001:0> Search.create(term: "baby") (0.1ms) begin transaction …
0
votes
2 answers

HABTM and belongsTo at the same join, cakePhp

I have a model Fix with a relationship HABTM Device model. Device model has a belongsTo to Device_type model, like this, for only getting the device type name: var $belongsTo = array('Device_type'=>array('fields'=>'name')); So, I need every Fix,…