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

Laravel BelongsToMany with array of ids as an attribute instead of individual id

Given: "users" table: [{ id: 1, school_ids: [1, 2, 3] // text type cast as array }] Then: "schools" table: [{ id: 1, name: 'school 1", }, { id: 2, name: 'school 2", }, { id: 3, name: 'school 3", }] I currently have a relationship…
I am L
  • 4,288
  • 6
  • 32
  • 49
0
votes
1 answer

Validating HABTM Checkbox's

I have multiple check boxes from a many to many relationship, And i'm trying to validate them so that none of the fields need a value to continue. At the moment if i try to create a user without assigning them to a group/role through the checkboxes…
ahmet
  • 4,955
  • 11
  • 39
  • 64
0
votes
0 answers

Laravel belongsToMany with multiple tables

I have a table called creative and two another tables called title_set and image_set. They relative with each other by the creative_set table. So basically, I have: creative: id title title_set: id title image_set: id …
Son Le
  • 229
  • 5
  • 16
0
votes
1 answer

How to eager_load attachments: 1+N problem not working with ActiveStorage attachments

I have a product list which gets serialized for an JSON API response For that I need also imageUrl which come from ActiveStorage attachments. I stumbled over the 1+N problem. As you can see, I already tried to include any kind of 'includes' And I…
0
votes
1 answer

Query on two HABTM models (Rails3)

I have two models, Clients and Items with a HABTM association. I would like to find the fastest way to select all Clients, which have several (more than one) of the items (or a certain number of items). class Client < ActiveRecord::Base …
0
votes
1 answer

CakePHP HABTM JoinTable w/Extra Field

So I have a customers table, a contacts table, and a contacts_customers join table, which also has contact_type_id field which maps to a contact_type table. I have used the information linked to from CakePHP update extra field on HABTM join table in…
0
votes
2 answers

how to get hasmany relation inside another relation in Laravel

how to get hasmany relation inside another relation in Laravel i want to get product optionGroup with product options i made this $try1 = Product::with(["optionGroups.options"])->find(1); but this return all group options i want to get product…
yemenpoint
  • 167
  • 3
  • 5
0
votes
1 answer

laravel belongstomany with pivot table doesn't get data

I have 3 tables :legalpursuit , guarantors, guarantors_legalpursuit. and I have Many To Many Relationships in my project. I save legalpursuit_id in legalpursuit / guarantors_id in guarantors / and both of them in guarantors_legalpursuit. I am using…
0
votes
1 answer

HABTM only working one way

I have Users and Events, and a shared table of events_users, and a HABTM between user/event set to this join table. User schema id, …, … Event schema id, user_id {this is the Owner of the event} events_users schema id user_id event_id user…
mondo
  • 3
  • 2
0
votes
1 answer

Rails HABTM joining with another condition

I am trying to get a list, and I will use books as an example. class Book < ActiveRecord::Base belongs_to :type has_and_belongs_to_many :genres end class Genre < ActiveRecord::Base has_and_belongs_to_many :books end So in this example I…
B_B
  • 1
0
votes
2 answers

Has_and_belong_to_many association

I have two models with no associations between them. So, I generated a migration and added an association. class Post < ActiveRecord::Base has_and_belongs_to_many :workspaces end class Workspace < ActiveRecord::Base has_and_belongs_to_many…
0
votes
2 answers

Hibernate error deleting child record Grails 4

I am having difficulty removing a child from an association. I'm using Grails 4.0.3. The two classes in question are the following: ShoppingCart: class ShoppingCart implements Serializable { private static final long serialVersionUID = 1 …
0
votes
1 answer

Form creation for a HABTM association

Here's what I'm trying to accomplish. I have courses that students register for. I want to track the advanced students in that class. I set up another model called course_results. class CourseAdvanceType < ActiveRecord::Base belongs_to :course …
alassiter
  • 505
  • 1
  • 5
  • 15
0
votes
1 answer

ActiveRecord::ConnectionNotEstablished error when using has_and_belongs_to_many

I am running into ActiveRecord::ConnectionNotEstablished error. I have the following code ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => 'users_vendors.db') Class User < ActiveRecord::Base has_and_belongs_to_many…
dmg
  • 608
  • 8
  • 15
0
votes
0 answers

Cakephp 4 Linking 2 existing entities with belongstomany association

First of all, thank you for your patience. I am getting to grips with PHP coding after a long while. I have finished the famous Cake tutorial and am now continuing with what I know and creating new solutions. I am creating a voting system. When the…