1,452 questions
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 ...
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", ...
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 ...
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<...
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, ...
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 ...
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:
...
-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(
...
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 :...
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:
...
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'...
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. ...
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 ...
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@...
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 ...
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 ...
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 ...
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-&...
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 ...
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> ...
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(){
...
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 < ...
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;
...
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, ...
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 ...
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 ...
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 ...
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. ...
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::...
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:
----------------------
| ...
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 ...
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');
}...
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, ...
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'...
-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 ...
-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 ...
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)
...
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 ...
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 ...
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.
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
...
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 ...
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 ...
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 "...
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,...
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 ...
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 ...
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 ...
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(...
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 ...