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

How to make form for creating polymorphic comments to Post and Picture models?

I need to create a form for post#show and picture#show views to create any comments for them. I'm created a polymorphic association and migration for these, but i need help to create form for them. ...
Alexander Abramov's user avatar
1 vote
1 answer
73 views

How to automatically derive foreign key column names with polymorphic associations?

In my Ruby on Rails 7 application I have a large Account model with various has_many associations (most of them are left out for brevity here): class Account < ApplicationRecord has_one :...
Tintin81's user avatar
  • 10.2k
0 votes
0 answers
36 views

SQLAlchemy: IntegrityError when trying to fill polymorphic table with duplicate entries

I have the below code where I'm using sqlalchemy to create a databse structure. When a person either changes their profession, location or salary, I would like to fill in the questionnaires table with ...
corianne1234's user avatar
-3 votes
1 answer
81 views

Segmentation fault occur [duplicate]

#include <iostream> using namespace std; struct A { virtual ~A() { cout << 0 << endl;}; }; struct B : A { int abc; ~B(){ cout << 3;} }; int main() { A* ...
Hardik's user avatar
  • 185
0 votes
2 answers
54 views

How can I get the associations from the polymorphic class to the related classes

I am trying to get some polymorphic associations to work properly but I am unable to get them right. Currently they give me whatever the ID matches for both tables instead of the direct relation. ...
Victor Luna's user avatar
  • 1,806
0 votes
1 answer
80 views

Insert into three-level joined tables using SQLAlchemy, ignoring duplicates on grandparent table

I am using SQLAlchemy to build a Postgres database. I am creating my schema like this: import datetime from typing import List, Optional import sqlalchemy as sa from sqlalchemy import orm, MetaData, ...
Logos Masters's user avatar
0 votes
0 answers
29 views

Polymorphic association with many belongs to one

I'm having this subscription table and this subscription table can have_many orders, and can have_many appointments. I was trying to create an polymorphic association so that subscription....
m.sahil Kumar's user avatar
1 vote
0 answers
483 views

How to handle polymorphic queries in GORM

I currently have the following models set up: type TextQuestion struct { gorm.Model Prompt *Prompt `gorm:"polymorphic:Question"` } type ChoiceQuestion struct { gorm....
chaaaun's user avatar
  • 11
0 votes
0 answers
44 views

Rails Polymorphic POST test failing

I have a polymorphic model Note: class Note < ApplicationRecord belongs_to :commentor, class_name: "User" belongs_to :notable, polymorphic: true, touch: true belongs_to :...
Chrismisballs's user avatar
0 votes
0 answers
485 views

How do I correctly structure & associate a delegated type and its associations within Rails?

In an effort to not have multiple of the same record/similar records I'm investigating using delegated_type however Im stumped on just how my associations should/would work. I've a table, Item that ...
ethanmclark's user avatar
1 vote
1 answer
489 views

How to write a Rails polymorphic association query with a join table

I have a many to many relationship through a polymorphic association and I'm having trouble writing my query Here's my migration: def change create_table :excuses do |t| t.string :label ...
Jeremy Thomas's user avatar
0 votes
1 answer
118 views

Laravel Polymorphic Limit Related Records

I have two models that I am working with - Traffic and Account. These two models have a polymorphic relationship as through an accountables table all with standard Laravel conventions. An Account may ...
Mike's user avatar
  • 43
1 vote
0 answers
400 views

Laravel saving polymorphic model doesn't have a default value

I'm working on a Laravel 9 project. I'm new to Polymorphic relationships and believe I need to define one. In my application, I have a parent model called Application that has a single ...
Ryan H's user avatar
  • 2,866
1 vote
1 answer
52 views

Sending a pointer to a polymorphic/derived type

I'm encountering the following schematic problem: A base class (defined as a regular type), let's call it base_a that defines a generic function A derived type, let's call it class_a that inherits ...
Re'em's user avatar
  • 11
1 vote
1 answer
204 views

Rails: How to create two records with has_one association at the same time

I have a Rails 6 app. The Hat model is in a has_one polymorphic relationship with the Person model. (I know this seems backwards. I'm not the author of this code.) The Person model creates the ...
emersonthis's user avatar
  • 33.2k
2 votes
1 answer
349 views

how to validate a polymorphic field association in rails?

Here is the question, I have a customer and address model as follows: class Customer < ActiveRecord::Base has_one :address, as: :addressable end class Address < ActiveRecord::Base ...
Samuel D.'s user avatar
  • 189
0 votes
1 answer
276 views

sequelize cli creating a polymorphic one to many and many to many relation

I want to create a polymorphic relation like in the diagram using sequalize-cli es6 format. I have created this model using sequelize-cli npx sequelize-cli model:generate --name Post --attributes ...
JAYANTA SINGH's user avatar
0 votes
1 answer
28 views

Access a different table from multiple possible ones on MySQL based on another's table attribute [duplicate]

I'm doing a personal database project on MySQL, where a user sells its vehicle and adds different information based on the vehicle type (electric, hybrid or combustion), and I need the 'vehicle' table ...
AbruptRope's user avatar
2 votes
1 answer
2k views

polymorphic relation in MySQL

First Question I wanted to make an polymorphic relation in MySQL. I had this post as an example: Creating a polymorphic association using MySQL Workbench My Question, with this solution an join doesn'...
Leon's user avatar
  • 165
0 votes
1 answer
40 views

Rails should relation be polymorphic?

I have 3 tables Injury, Sport, Exercise. I'm trying to wrap my head around if I should create a relation between them. I want to be able to list Injuries in the Sports and Exercises tables; this might ...
Chrismisballs's user avatar
1 vote
1 answer
44 views

Rails polymorphic where

I have a polymorphic model class BankFacility < ApplicationRecord belongs_to :facility_group belongs_to :facility, polymorphic: true end the bank facility could have many types of faciltiis ...
hany 's user avatar
  • 11
0 votes
0 answers
286 views

Laravel get nested relationship from polymorphic table

I want to get nested relationship data from polymorphic table, I'm using MongoDB as database in my laravel app so you might notice that i don't use pivot table between movies and genres table for many ...
Ibrahim Ahmad's user avatar
1 vote
2 answers
812 views

One To Many Polymorphic relationship - Call to undefined method getConnectionName()

I have followed the documentation very closely but something isn't working https://laravel.com/docs/9.x/eloquent-relationships#one-to-many-polymorphic-relations I am trying to add permissions into ...
Matthew Appleby's user avatar
0 votes
2 answers
503 views

Laravel: complex Many to Many Polymorphic Relationship for conditions and actions

The Method model is a container of conditions (triggers) and actions. A Method has multiple Condition Each Condition has multiple Action We can have different types of Condition, for instance: ...
Programmeur's user avatar
  • 1,531
1 vote
2 answers
521 views

Polymorphic relationship in Django

I have this relationship between my models: The model called MyModel might have a foreign key to model A or model B, How can I do this in Django? I heard that the solution called Polymorphic ...
Baghdadi's user avatar
0 votes
2 answers
1k views

Managing polymorphic data in Rails

I have an application where a User can create many Links, and each Link can store different type of data, depending on what type of Link it is. For example, a TelephoneLinkData stores a telephone ...
Sebastian Rollén's user avatar
0 votes
1 answer
272 views

Rails has_many through multiple alias for same model

I have 3 Models. Archive -> ArchiveJoin <- Contacts ArchiveJoin is a polymorphic join table. I want to be able to associate Archive and contacts through the join table and be able to query them ...
ls168's user avatar
  • 37
-2 votes
1 answer
659 views

Mysql can we have foreign key reference to multiple columns with OR condition?

I'm gonna migrate multiple DBs to one DB, all those DBs have same tables, the problem is duplicate keys, so for this reason I thought the easiest solution is to have ex_id in my main tables and then ...
jones's user avatar
  • 1,453
0 votes
1 answer
148 views

rails polymorphic association on 1 model

Does rails provide multiple polymorphic association. And allow has_many relation. class Picture < ActiveRecord::Base belongs_to :image, polymorphic: true belongs_to :icon, polymorphic: true ...
Suhas Mv's user avatar
0 votes
1 answer
509 views

Class Diagram to Entity-Relationship Diagram (Relationships and Cardinality)

Are the multiplicities of associations and aggregations in an UML class diagram the same as the cardinalities of the relationships in a relational database (Entity-Relationship Diagram)?
Jamal's user avatar
  • 35
2 votes
1 answer
46 views

mysql - how to join with dynamin column in table

I have three tables like the following: calls_list (table) id line rel_type rel_id 1 3 user 2 2 10 lead 1 users (table) id name phone 1 mehran 99999 2 reza 222222 leads (table) id title ...
mehran_s_w's user avatar
0 votes
1 answer
889 views

Rails polymorphic association without using id column (using different column)

I have a polymorphic table with signable_id and signable_type. Class Login belongs_to :signable, polymorphic: true end the signable can be either User or Account. Class User has_many :logins, ...
Suganya Selvarajan's user avatar
0 votes
1 answer
669 views

has_one :through association error: Cannot have a has_one :through association where the :through association is a collection

I have the models Subscription, SubscriptionCart and Invoice. A subscription has_many :subscription_carts, and a subscription_cart has_many :invoices. I need to associate a Subscription with an ...
pinkfloyd90's user avatar
1 vote
1 answer
292 views

Django Many to Many - polymorphic

In a Django application, I have three models: Service Product AppliedTax I want to create a many-to-many relationship between Service and AppliedTax and between Product and AppliedTax. Normally I ...
manosagent's user avatar
0 votes
0 answers
28 views

Polymorphic relationship and querying conundrum

I'm building a DB for a logistics system It consists of 3 main models: Users, Requests and Carriers. Request gets created by a User and later a Request gets assigned to a Carrier. Important: There's a ...
luigi7up's user avatar
  • 5,942
2 votes
0 answers
42 views

Enforcing single relationships between Laravel models

I am designing an application for school portal and I have three models: User Teacher Student And maybe a pivot table "school_user". Where User could be either Teacher or Student but not ...
Mr. Fox's user avatar
  • 21
0 votes
1 answer
81 views

Rails - how can I make a profile switch on a radio button using a device and polymorphic associations?

I am new to development on rails. I need help with customizing the device. I have user with polymorphic association - profilable. When registering, I need to fill in the profilable depending on the ...
Tsvetkov Maksim's user avatar
1 vote
1 answer
86 views

[Rails][Postgres] How to order users by most posts in a category?

I am struggling to achieve this I have 3 models, User (has_many :posts) Post (Belongs_to :user, HABTM :categories) Category (HABTM :posts) Now, let's say I want to find and order all users who have ...
HighOnRails's user avatar
0 votes
1 answer
980 views

Call to a member function getRelationExistenceQuery() on bool

I have three tables - locations, sectors, touchpoints. They are joined with many to many polymorphic relationships. When I try to get my sectors filtered by location with this query $sectors = ...
Aaron Harker's user avatar
0 votes
1 answer
324 views

Polymorphic comments with nested resources in Ruby on Rails

I've followed the Go Rails tutorial below to set up comments with polymorphic associations: https://gorails.com/episodes/comments-with-polymorphic-associations However, I have a nested situation with ...
spinachbro's user avatar
0 votes
1 answer
617 views

Sequelize polymorphic many to many - `add` mixin not working

I have a many-to-many polymorphic association setup for customer surveys. The issue that I have run into is when using the add mixin on the model instance of Survey. If the joining table already has ...
Avraham's user avatar
  • 968
0 votes
1 answer
504 views

Active Storage with Single Table Inheritance and different attachables (STI) #43780

I'm using ActiveStorage in a solution I'm building to create documents with a block builder like interface, but I'm running into the N+1 query problem when using STI in combination with active storage ...
Jens's user avatar
  • 1,144
0 votes
0 answers
312 views

How to get the Hierarchy recursively in laravel

I have 2 tables i.e. users and user_managers, with the following structure and data: users id name employee_number 1 Employee One ACB1234 2 Employee Two XYZ1234 3 Employee Three EFG1234 4 ...
Dakota Jhonson's user avatar
1 vote
0 answers
109 views

Rails polymorphic association: Struggling with form to input tags

I have a model with movies and actors and I want both to be taggeable. I know there's a gem for that but I thought I'd teach myself polymorphic associations :) Basic functionality works (I can do ...
tkhobbes's user avatar
  • 642
1 vote
0 answers
21 views

rails 2.2 - polymorphic has_many without using has_polymorphs

I'm trying to set up some new classes and associations in a Rails 2.2.2 app (please don't ask me to upgrade it). The idea is that there is a Conversation class. It can have many participants, which ...
Max Williams's user avatar
  • 32.8k
0 votes
1 answer
1k views

Rails: Check associated belongs_to object type in a polymorphic relation

I have three models: class Product belongs_to :object, polymorphic: true belongs_to :membership, foreign_key: :object_id belongs_to :ticket, foreign_key: :object_id end class Membership end ...
HJW's user avatar
  • 392
-2 votes
1 answer
338 views

Liking a comment in rails [closed]

I have been learning rails and building blogs site and introduced the like model for posts. I have created a like model for liking a blog post using polymorphic association with user user_id and blogs ...
Abhishek Singh's user avatar
0 votes
2 answers
458 views

polymorphic laravel morphTo?

I want to create a somewhat polymorphic laravel morphTo. I want to create multiple 'dimension' polymorphic properties but don't see a need to create four separate (identical) tables for their values (...
Scott's user avatar
  • 8,057
0 votes
1 answer
29 views

Changing model to polymorphic and maintain relationship

I have 2 models, Payment and Consultation. Previously Payment belonged to Consultation and had consultation_id as an attribute. I've now made the relationship polymorphic but I'd still like to be ...
Jeremy Thomas's user avatar
1 vote
1 answer
75 views

Rails polymorphic has many through

I'm trying to do the following but getting a bit confused about how to setup the polymorphic has many through. Class Topic end Class Post end Class Podcast end Class ResourceTopics # ...
Brad's user avatar
  • 8,536

1
2 3 4 5
27