Skip to main content
The 2024 Developer Survey results are live! See the results

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

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

has-and-belongs-to-many
0 votes
0 answers
34 views

HABTM relationship / validates associated: valid? is true even though I don't think it is

I made the following join table to be used in a HABTM relationship between tasks and itself: create_table :tasks_tasks, id: false do |t| t.belongs_to( :dropoff_task, null: false, ...
rwg05's user avatar
  • 127
2 votes
0 answers
46 views

How can I query to get results with belongsToMany in Laravel

UPDATE I could solve the problem. Posting the update. First of all, thank you for taking your time answering this threat and helping me. I'm creating a courses website with Laravel 10, and I'm trying ...
Juan Rincón's user avatar
0 votes
1 answer
38 views

Laravel Eloquent: belongsToMany to return an array of strings instead of array of objects

I have two tables that are connected with a pivot table. shows: +----+--------+ | id | show | +----+--------+ | 1 | show1 | | 2 | show2 | | 3 | show3 | +----+--------+ draft_types: +----+-----...
pbrune's user avatar
  • 470
0 votes
1 answer
29 views

Validate BelongsToMany attached keys exists

How to validate foreign keys (as UUID) in attached elements like below: $user->languages()->attach([ '9a347a21-b6db-42ae-85a5-24a270946eec' => [ // UUID of language '...
kicaj's user avatar
  • 2,920
0 votes
1 answer
29 views

Inject/merge medialibrary items into belongtomany relation in laravel

I have json like this: "member_skills": [ { "id": 69, "skill_type_id": 6, "title": "Piano", "created_at":...
saber tabatabaee yazdi's user avatar
-1 votes
1 answer
127 views

for has_and_belongs_to_many table name should be in singular or plural

for has_many we will use plural definitely for belongs_to we will use singular for ex: has_many :users belongs_to: user But for has_and_belongs_to_many has_and_belongs_to_many :user, join_table: :...
Mooventhan's user avatar
0 votes
0 answers
136 views

Laravel/Eloquent BelongsToMany and globalScopes

In short - I would like to define global scope that would filter related instances by the value of the field in pivot table. I have defined the next relationship: class Client extends Model { ...
dmikam's user avatar
  • 1,052
1 vote
1 answer
30 views

Laravel working with belongsToMany and extra fields

I am trying to save a simple belongsToMany relation into my database. First, my table: Schema::create('user_activity_log', function (Blueprint $table) { $table->unsignedBigInteger('...
Hardist's user avatar
  • 1,965
0 votes
0 answers
39 views

Pivot table pagination doesn't work in laravel 8

I am doing an assignment for my study, here the code Category Models It have books method that pivot table Books and Categories <?php namespace App\Models; use Illuminate\Database\Eloquent\...
CastCast's user avatar
0 votes
1 answer
38 views

Ruby on Rails: Many-to-many relationship on the same table as a one-to-many relationship

I am learning Ruby on Rails and am currently struggling to implement a many-to-many relationship. I have a user and a carpool that can be driven by a user and ridden by multiple users. So, I am trying ...
Michael's user avatar
  • 51
1 vote
0 answers
32 views

how to eager load a has_and_belongs_to_many association in mongoid?

I have a habtm association in a rails app using mongo / mongoid class A has_and_belongs_to_many :bs, inverse_of: :as end class B has_and_belongs_to_many :as, inverse_of: :bs end and i want ...
user1130176's user avatar
  • 1,836
0 votes
1 answer
36 views

Adding data to jointable in a loop after adding data to one of the joint models Cakephp2

So im making an online shop where i want to make each purchase have multiple products. I have the tables products, purchases and product_purchases. I want this function to add a row to purchases (that ...
Antonio Carreño Arnedo's user avatar
0 votes
1 answer
43 views

How to filter common users from multiple belongstomany relationship pivot tables in laravel

There are table diagram Sellers table are main table. Services and Areas tables can contain multiple services and areas for spacific Seller. For this I use seller_services and sellerable Pivot table ...
Moenul Islam's user avatar
0 votes
2 answers
54 views

I am trying to render only those items that belong to another controller in React

I am working on a travel planning web app project in Rails and Ract. In my Ruby on Rails backend I have a model Place that belongs to my model Trip. in React.js on the frontend I am trying to render ...
Robyn S's user avatar
1 vote
0 answers
49 views

laravel belong to many not working -- "1048 Column 'purchase_id' cannot be null"

I am trying to store multiple purchaseCategory using Laravel and Vue, but after clicking submit I am getting this error. How do I solve it? 1048 Column 'purchase_id' cannot be null In my Vue file I ...
16_018_RHR's user avatar

15 30 50 per page
1
2 3 4 5
92