Skip to main content
Filter by
Sorted by
Tagged with
0 votes
1 answer
31 views

Problem to get records using hasMany and orWhere in Laravel

I have hasMany relation in User model: public function wins() { return $this->hasMany(Win::class, 'user_id', 'id'); } I want to get records from winners table, "where user_id = 5865535 ...
Ikenitenine's user avatar
0 votes
1 answer
44 views

Rails dependent (nullify or destroy) in one action

I have this following relationship between 2 models: class Transaction < ApplicationRecord has_many :transfer_sources, dependent: :nullify, foreign_key: "transaction_source_id", ...
Steve Folly's user avatar
  • 8,587
0 votes
1 answer
46 views

Laravel HasMany through composite key

I have 1:N relation where parent table LOCATIONS contains fields server_id and location_id and table DEVICES is related to the LOCATIONS throught fields server_id and location_id. How can I establish ...
Čamo's user avatar
  • 4,153
0 votes
0 answers
45 views

sequelize getter in HasMany error TypeError: is not a function

I want to make a getter beetween two table. In the controler of one who get in the other, the getter is not a function. The model Comitee who as many club export class Comitee extends Model<...
Huyenlong's user avatar
0 votes
1 answer
85 views

Should we add validation to through model in Rails?

class Product < ActiveRecord::Base has_many :collaborators has_many :users, :through => :collaborators end class User < ActiveRecord::Base has_many :collaborators has_many :products, ...
Kevin's user avatar
  • 1
0 votes
1 answer
47 views

How to access drop-down relationships in Laravel

Models : USER boards() : HasMany BOARD lists() : HasMany LIST tasks() : HasMany TASK Tables : Board : id user_id List : id board_id Task : id list_id How do I want to search for a task ...
none's user avatar
  • 97
1 vote
0 answers
119 views

Laravel hasOne with two matching fields

I need to establish a hasOne relationship that matches two fields simultaneously. Here's my users table: ID user conc name 1 JDoe ABC John Doe 2 JDoe ZXC John Doe And here's my membership table: ...
mps's user avatar
  • 465
-1 votes
1 answer
38 views

Laravel order with GREATEST with MAX by two columns

I looking-for solution to order/sort by relation (hasMany) fields, with max value of two columns. I prepare starter kit: https://www.db-fiddle.com/f/m371fzUJuQp9dX1yKm4yEm/3 SELECT GREATEST( ...
kicaj's user avatar
  • 2,948
0 votes
1 answer
42 views

Is there a way to create a has_many association that just filters items from another has_many association?

Basically I have a has_many association. I want to create another association that just filters items from the original association. class Track belongs_to :playlist end class Playlist has_many :...
acanthite's user avatar
  • 153
2 votes
2 answers
447 views

Issue with ActiveRecord association: "The Lap model class is not an ActiveRecord::Base subclass"

I'm facing a strange issue with an ActiveRecord association in my Ruby on Rails project. When I try to access the laps association method from my User model, I get a peculiar error. Error: ...
ranska's user avatar
  • 33
0 votes
1 answer
54 views

error with Attempt to read property "taqseet" on null while it not null laravel

I am trying to fix all issues but I get Attempt to read property "taqseet" on null. Student Model public function taqseet() { return $this->hasMany(Taqseet::class, 'stud_prog_id', 'id'...
user6594805's user avatar
2 votes
2 answers
848 views

EF 7 Unidirectional many-to-many error: Every skip navigation must have a configured foreign key

following official doc i setup my objects in that way but got OneTimeSetUp: System.InvalidOperationException : The skip navigation 'Contatore.Workflow1' doesn't have a foreign key associated with it. ...
gt.guybrush's user avatar
  • 1,378
0 votes
1 answer
92 views

Ruby on Rails ActiveRecord - has_many with Custom Join on Aliased Table

Context: I have three models: User, ProjectUser, and Message . Messages have a polymorphic join via item_id and item_type and can belong to either a User or a ProjectUser Users have many ...
Ric Donati's user avatar
0 votes
1 answer
51 views

Laravel | Fetch query results by matching multiple where conditions on multiple columns

I have two tables , users and user_skills Schema Design. Each user can have multiple skills where there are experience in number of years associated with each skills . users id name email age 1 A a@...
pantech123's user avatar
0 votes
1 answer
33 views

How do I correctly update User state in React with a has_many :trails, through: :reviews association, after deleting a review?

ERD for my API Users have many reviews, and many trails through reviews, and vice versa. Goal: On a user profile page, render a list of names of trails that user has reviewed, without duplicating any ...
Cody Barker's user avatar
5 votes
2 answers
7k views

How to cascade a DELETE in GORM?

I have tried everything I could think about to obtain a cascaded delete in GROM (deleting an object also deletes the tree of objects below). The code below is an attempt to do that and I tried with a ...
WoJ's user avatar
  • 29.8k
0 votes
1 answer
170 views

When to use both BelongsTo and HasMany?

I use an ORM in Golang (GORM) and I am trying to understand if (and when) I should use both HasMany and BelongsTo relationships. I understand that using: HasMany allows me to query the children ...
WoJ's user avatar
  • 29.8k
0 votes
1 answer
133 views

Error 'Array to string conversion' when trying create hasMany relationship model laravel 10

Here is my code in model Pos ` /** * Get all of the details for the Pos * * @return \Illuminate\Database\Eloquent\Relations\HasMany */ public function details(): HasMany { return $this-&...
Muhammad Ilham Shobirin's user avatar
1 vote
0 answers
65 views

How do I reset GORM has-many backreference on delete?

I would like to create a has-many association in GORM with a backreference using the owner's ID. When I create an association using the Append() method, the backreference gets filled in correctly. But ...
Gergely Nagy's user avatar
0 votes
0 answers
23 views

Fluent Nhibernate HasMany Duplicate Insert Problem

I Have Duplicate Insert Problem. When i try insert duplicate rows public class CostRegister : Entity<int> { public virtual IList<CostDocumentRegister.CostDocumentRegister> ...
Rasim Kaptan's user avatar
1 vote
1 answer
34 views

Relationships laravel doesn't work after 5th position

I have 2 models: model 1 -> hasMany(model2) public function model2(){ return $this->hasMany(Model2::class, 'field_fk_id'); } model 2 -> belongsTo(model1) public function model1(){ ...
Robert Blasco Villarroya's user avatar
0 votes
0 answers
50 views

Rails nested ressources - missing required keys: [:entry_id]

I have two models: class Credit < ApplicationRecord belongs_to :user has_many :entries, -> { order(position: :asc) }, dependent: :destroy end class Entry < ...
Jan's user avatar
  • 259
1 vote
1 answer
987 views

Sequelize Error: You have used the alias values in two separate associations. Aliased associations must have unique aliases

This is my code: public getSpecs = async (req: Request, res: Response, next: NextFunction) => { try { const MasterSpecCategory = models[res.locals.project].master_spec_category; ...
Meet Savaj's user avatar
0 votes
1 answer
29 views

Can't call destroy_all for ActiveRecord if validates_associated is defined for relation in Rails model

I've defined two models and added the validation of presence one device per car (we need to keep has_many devices for future requirements): class Device < ApplicationRecord belongs_to :car, ...
Oleksandr Bratashov's user avatar
1 vote
1 answer
56 views

Rails: List of a nested items through a many-to-many relation model

I am new to rails and there's something I don't fully understand. I have 4 models as follows: class Unit belongs_to :compound belongs_to :unit_type end class UnitType has_many :units has_many ...
KhogaEslam's user avatar
  • 2,996
0 votes
1 answer
1k views

Looking for the right way to create and update item with GraphQL in Amplify / React

I'm new to Amplify, React, and GraphQL. I'm looking to figure out the right way to make a mutation that has an @hasMany relationship between tables (for context, I am using a multi-table solution ...
femmedecentral's user avatar
1 vote
1 answer
42 views

build_association with has_many Rails

I want to build associated records for non-persisten record in rails. Let's say I have these models: class Post has_many :comments end I want to do something like this: p = Post.new(text: 'Some ...
aldm's user avatar
  • 379
0 votes
1 answer
188 views

Laravel hasManythrough?

I have three models creating a many-to-many relationship ModelA(id) ModelB(A.id,C.id) ModelC(id,name) How to fetch C.name using model A? Currently model A hasOne model B, and model C hasMany model B. ...
Mir123's user avatar
  • 3
0 votes
0 answers
31 views

How to retrieve array of results of (has-many) relationship

I have users table (id,email...etc) and related table user_devices(user_id,device_id) user has many devices In User Model public function userDevices() { return $this->hasMany(userDevicess::...
Ahmed khaled's user avatar
0 votes
2 answers
37 views

Rails: multi find out if a category has members with a single fast query

Given the model: Member -> belongs_to :category Category -> has_many :members I would like to know for every category whether or not it has members, in the style of: ---------------------- | ...
Kalsan's user avatar
  • 1,029
1 vote
1 answer
69 views

Can html attributes (other than class) have more than one value assigned to them?

Apart from the class attribute that can have many values, I'm wondering if there are other attributes in html where I could do the same, add multiple attributes separated by spaces? If so, could you ...
Andrea's user avatar
  • 13
2 votes
1 answer
62 views

Laravel save HasMany realtion

I have a set that has a list of group and each group has a list of attributes like this //sets Schema::create('sets', function (Blueprint $table) { $table->id(); $table->string('name'); }...
GAOUL's user avatar
  • 138
1 vote
1 answer
66 views

Eager load Rails' has_many with two primary_keys and foreign_keys

I have two models class TimeEntry < ApplicationRecord belongs_to :contract end class Timesheet < ApplicationRecord belongs_to :contract has_many :time_entries, primary_key: :contract_id, ...
23tux's user avatar
  • 14.7k
0 votes
1 answer
32 views

Method hasMany Laravel not working in Web Hosting

I have problem in my method hasMany Laravel. When i use in my file local, it's worked. But, when i hosting my file to web hosting it's not working. I don't know what the problem, because my data can'...
Muhammad Fahmi's user avatar
-1 votes
1 answer
60 views

How to create association with limit of items on rails

I have a model with doctor and patients with associations: Class doctor has_may :patients Class patient belongs_to :doctor I need to make limit of free payment patients and other limit for payed ...
Andrew Kancev's user avatar
-1 votes
1 answer
277 views

How can we load the Relationship in Laravel with sum of different column?

I'm trying to get the sum of three different columns using Laravel query builder. I want to calculate the sum of 3 subjects. for example, Student table contains information and record table have marks ...
Arbaz Khalid's user avatar
0 votes
1 answer
118 views

How to override rails has_many cache

I want to be able to manage has_many caching myself. The issue being I want to be able to archive (like soft delete, but with discardable gem) some records: has_many :tags def tag_list=(tag_names) ...
Nathan Gouy's user avatar
  • 1,412
1 vote
0 answers
444 views

Golang GORM `has many` or `many2many` association append with condition

I'm using gorm to manage my database, but here is a problem: How to append to an association with condition? Let me explain more detail: example struct(model) code type Group struct { ID ...
Jobber T's user avatar
0 votes
1 answer
378 views

How to perform calculations in hasMany relationship in Laravel (Best Practices)

I know that there are many great functionalities within Eloquent and relationships in Laravel, however, there are times that we need to perform various calculations based on the relationship data. My ...
Akmal Arzhang's user avatar
0 votes
1 answer
103 views

Doesn't Laravel eloquent hasmany allow multiple columns?

return $this->hasMany(Key::class, 'order_id' , 'order_id')->with('supplier'); How can I add a 2nd condition here, both order_id must be equal to order_id and game_id must be equal to game_id.
yktibrahim's user avatar
3 votes
0 answers
453 views

sequelize-typescript .$set doesn't set hasMany relationship

I have these two models: @Table export class Role extends Model { @PrimaryKey @Column({type: DataType.UUID, defaultValue: DataType.UUIDV4}) declare id: string @Column name: string ...
Ionel Lupu's user avatar
  • 2,791
0 votes
1 answer
1k views

What is the best way to update a has_many association when creating, updating and removing in the same request using Rails?

I am looking to update a has_many relationship. The data being received from the request may have data to be created, some data may need updating to new values and some data may no longer be in the ...
James Parsons's user avatar
0 votes
1 answer
423 views

Is there a way of accessing records from a non persisted association?

I have the following classes: class Post < ApplicationRecord ...
Joe Cabezas's user avatar
  • 1,517
0 votes
1 answer
59 views

Rails 6.0 has_many - belongs_to failing to identify the foreign key

I have the 2 models Loan::Transaction and Loan::Transaction::Transition. They are both inside the folder "models" and inside "loan". The second is also inside the folder "...
Bruno Aguiar de Souza's user avatar
0 votes
2 answers
1k views

In Laravel hasMany relationship How to use with and where?

In Job model : public function jobApplications() { return $this->hasMany(JobApplication::class, 'job_id'); } In JobApplication Model public function jobs() { return $this->belongsTo(Job::class,...
Vishnu kk's user avatar
1 vote
0 answers
201 views

How to pass a parameter from a Laravel controller to a model hasmany function

I have an app with categories and subcategories, and I need to translate all of them to multiple languages. I want to retrieve all of the categories with their subcategories, along with any ...
MrMoxy's user avatar
  • 412
0 votes
1 answer
114 views

Count number of elements via Laravel relationship

There are different types of boards, types can have multiple boards, and boards have multiple users. Task: get the number of users for a specific type of boarding. Model for types boarding: class ...
vottiv's user avatar
  • 3
0 votes
1 answer
960 views

upload multiple files - Laravel

I already have a project in which I can upload multiple images, but I am missing the most important thing, being able to relate them to a post id number or record from another table. I am doing the ...
Sr. Miyagui's user avatar
0 votes
1 answer
125 views

Eager load extended has_many association

Couldn't find anything about how to specify extended association with arguments in includes. Condsider: Class Author < ActiveRecord::Base has_many :books do def of_genre(genre) where(...
sifear's user avatar
  • 87
0 votes
1 answer
65 views

Add.php Form->control not building the proper <select> for the belongsTo association

I'm trying to learn CakePHP and running into some issues (maybe just my misunderstanding) with the ways associations are handled. I have a RESULTS table with a composite key made of two foreign keys ...
EmilienKopp's user avatar

1
2 3 4 5
30