1,374 questions
0
votes
0
answers
46
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,
...
2
votes
0
answers
48
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 ...
1
vote
1
answer
64
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:
+----+-----...
0
votes
1
answer
40
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
'...
0
votes
1
answer
33
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":...
-1
votes
1
answer
135
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: :...
1
vote
0
answers
200
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 {
...
1
vote
1
answer
35
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('...
0
votes
0
answers
46
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\...
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 ...
1
vote
0
answers
36
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 ...
0
votes
1
answer
39
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 ...
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 ...
0
votes
2
answers
55
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 ...
1
vote
0
answers
53
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 ...
1
vote
0
answers
23
views
Relationship between pivot tables - return resource do not found using pivot or belongsToMany
good afternoon!
I would like some help from them regarding the scenario below:
I have 3 tables, 1 is the Moviment which is the main one, the 2 is the cart_moviments which is the secondary one which ...
0
votes
0
answers
133
views
How to implement a belongstTo with cakePhp 4 with conditions and different data types
My design has two models ModelOne and ModelTwo. In ModelOne there is an integer field which passes as a foreign key to ModelTwo as a varchar.
The original implementation from a previous version (...
0
votes
1
answer
516
views
Laravel 9.* belongsToMany with belongsToMany
I have DB structure:
user
user_id
office
office_id
project
project_id
role
role_id
permission
permission_id
role_permission
role_id
permission_id
...
0
votes
0
answers
90
views
Multiple hasMany or belongsToMany relationships
I have two models Category and Object and relationship table object_has_categories.
Category:
public function objects() {
return $this->belongsToMany(Object::class,Object::TABLE_CATEGORIES,...
-1
votes
2
answers
484
views
How to deal with 2 different type of associations with same table in rails?
I am creating my first rails application and stuck at this point for a long time.
So I have two models in my project.
Users (created through devise gem)
Projects
There are two associations of these ...
0
votes
1
answer
367
views
How to compare Query conditions from a BelongsToMany association in CakePHP 4.x?
I have a working Posts, Categories and Tags relationship. (Posts BelongsTo Categories and BelongsToMany Tags.) They work just fine at my view and index actions with no issue.
Now, for a simple "...
0
votes
0
answers
21
views
Laravel : retrieve other relationship from relationship called
So, i have this collection that i've been convert toArray , this is my collection :
array:1 [▼
0 => array:14 [▼
"id" => 1
"timeout" => "2022-05-29 15:15:34&...
0
votes
2
answers
753
views
Additional conditions on a belongsToMany relation on the intermediate table
When using the belongsToMany relation in Laravel Eloquent, is it possible to add additional conditions for the intermediate table? Currently, the inserts are duplicating and I am just trying to ...
0
votes
1
answer
725
views
Error "Array to string conversion" in relationship belogsToMany in laravel 8
I save data reqNumber in master table
in model product
public function orders(){ return $this->belongsToMany(Order::class); }
in model order
public function products(){ return $this->...
0
votes
1
answer
104
views
BelongsToMany independent child's relations - Laravel/Eloquent
Model structure:
FoodCategory - hasMany: Food
Food - belongsToMany: AccessoryGroup | belongsTo: FoodCategory
AccessoryGroup - hasMany: Accessory | belongsToMany: Food
Accessory - belongsTo: ...
0
votes
2
answers
492
views
Deep relations, *child* relation depends on *great-grandparent* id - with | load - Laravel/Eloquent
I have this DB/Model structure (example):
*Food Category ------------ (id, name) - *irrelevant
Foods ---------------------- (id, food_category_id, name, ...)
Accessory Groups --------- (id, name, ...)
...
0
votes
1
answer
81
views
Get items with Rails relations
I have two models with a relation like this:
class Ticket < ActiveRecord::Base
belongs_to :group
end
class User < ActiveRecord::Base
has_and_belongs_to_many :groups
has_many :tickets, as: :...
0
votes
1
answer
220
views
Rails model custom validation having one type of association
I have a model User which have has_and_belongs_to_many associations.
app/models/user.rb
has_and_belongs_to_many :advisors, dependent: :destroy
has_and_belongs_to_many :teams, dependent: :destroy
I ...
1
vote
1
answer
780
views
Elixir Ecto: Casting multiple belongs_to relationship in a schema goes wrong
First of all: I have a schema players and a schema matches and I want to establish belong_to, has_many relationship between them in phoenix 1.6. What I have tried:
defmodule TennisPhx.Matches.Match do
...
0
votes
2
answers
137
views
How to share a Rails model with other Devise users in read-only mode?
In a Rails 5 application, I have a shortlist model in a HABTM relationship with a user model, with the users controlled by Devise. This is all working as expected, where each User can see their own ...
0
votes
2
answers
184
views
Rails migrations: many-to-many relationship between the same class | Interpersonal Relationships
I want to connect two People with the help of Relationship.
Person:
* id
* name
Relationship:
* person_a_id
* person_b_id
* connection # an enum with values like "colleagues", "friends&...
1
vote
1
answer
1k
views
Laravel - Eager Loading BelongsToMany Relationship
I have one to many relationship between two entities/tables.
/**
* Get all of the products.
*/
public function products()
{
return $this->belongsToMany(Product::class)...
3
votes
2
answers
1k
views
Laravel Eloquent find posts that has all the given tags
Consider 3 tables as below
class Post extends Model
{
public function tags()
{
return $this->belongsToMany(Tag::class, 'post_tags', 'post_id', 'tag_id');
}
}
posts table
|id | ...
2
votes
0
answers
386
views
How to make belongsToMany relation respect global scopes defined inside pivot model
Lets say I have a User, Roles and User_Role table. I have a custom pivot model for my User_Role table. In a User model I have a relation like this
public function roles()
{
return $this->...
1
vote
1
answer
1k
views
Laravel 8 Nova: Customize Reationship BelongsToMany options, displayUsing and resolveUsing don't work
In a Nova resource, I show a BelongsToMany Nova Field. I would want to simply concatenate (prepending) a "check pictogram" before options values of this field, if they are already attached ...
1
vote
2
answers
2k
views
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&...
0
votes
0
answers
358
views
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
...
1
vote
1
answer
578
views
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 ...
-1
votes
1
answer
846
views
Laravel - Add additional where constraints from Eloquent Model belongsToMany relationship
I am new to Laravel (using v7) so I apologise if I am doing this incorrectly.
I have a custom subscription setup for my users.
I have my users table
id
first_name
last_name
1
John
Doe
2
Jane
Doe
I ...
0
votes
2
answers
4k
views
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
votes
1
answer
805
views
How to get posts by current tag and category simultaneously in Laravel?
I have Post, Tag and Category models. I know how to get posts by tag or posts by category. But I need to get posts by chosen tag and category simultaneously (at one time). Can somebody help? I use ...
0
votes
1
answer
474
views
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 ...
1
vote
1
answer
44
views
How to do a query on has_and_belongs_to in Rails with AND across the join instead of OR?
This may be a simple issue but I'm struggling. Here's what I'm trying to do:
I have a class, let's call it Car that HABTM Features. So:
class Car < ApplicationRecord
has_and_belongs_to_many :...
1
vote
0
answers
51
views
CakePHP 4.x : How to create a set of form controls that list all of the values in a HABTM (through) association?
I'm trying to create single edit form based on contacts that allows me to update/add skill levels for all the skills even if the contact doesn't already have a rating.
Something like:
Edit Contact
...
-1
votes
1
answer
119
views
hasManyThrough relations ships with join?
I have 4 tables (Cars, Vignettes, Inspections and Insurances). Vignettes, Inspections and Insurances are "belongsTo" to Cars.
I need to combine results of these three tables into one query ...
5
votes
0
answers
318
views
Laravel Jensseger Mongodb belongsToMany additional fields
the documentation says
"The belongsToMany relation will not use a pivot "table", but will push id's to a related_ids attribute instead. This makes the second parameter for the ...
0
votes
2
answers
68
views
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 ...
0
votes
2
answers
86
views
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 {
...
0
votes
0
answers
156
views
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 ...
0
votes
1
answer
22
views
Ruby HABTM association loop
i want to achieve a nested loop without duplicates in a have and belongs to many relationship
i have a model 'campaign' and for each campaign i also have campaign data.
i want to display each campaign ...