polymorphic-associations Questions
2
Is it possible to use delegate with has_many or has_one association in a polymorphic model? How does that work?
class Generic < ActiveRecord::Base
...
belongs_to :generable, polymorphic: tru...
Dortheydorthy asked 1/11, 2012 at 15:52
1
Solved
Introduction:
I have these Tables with their Models:
addresses table --> Address model
users table --> User model
companies table --> Company model
properties table --> Property model
...
Annisannissa asked 11/6, 2018 at 3:33
1
Solved
The recommended way to handle polymorphic associations in Phoenix seems to be adding an intermediate schema that contains the references to the other schemas:
Inverse polymorphic with ecto
https:...
Schoolbag asked 16/3, 2018 at 19:38
5
Solved
I have a table which stores comments, the comment can either come from another user, or another profile which are separate entities in this app.
My original thinking was that the table would have...
Straight asked 27/5, 2010 at 6:2
3
Solved
class Transaction < ActiveRecord::Base
belongs_to :account, :polymorphic => true
end
class Bankaccount < ActiveRecord::Base
has_many :transactions, :as => :account
end
class Creditc...
Anthelion asked 17/1, 2010 at 3:32
4
Solved
I have a Products table and want to add a column:
t.references :imageable, :polymorphic => true
I was trying to generate migration for this by doing:
$ rails generate migration AddImageableT...
Carotenoid asked 4/4, 2011 at 4:31
0
Say we have two classes that each implement an interface, IParent, as follows:
public class Foo : IParent
{
public long Id { get; set; }
...
public IList<Child> Children { get; set; }
.....
Bradley asked 29/8, 2017 at 16:34
4
If I have a polymorphic association between 3 models as:
Comment
belongs_to :book, :class_name => 'Book', :foreign_key => 'ref_id', conditions: "comments.ref_type = 'Book'"
belongs_to :art...
Ailey asked 26/6, 2017 at 19:58
3
Solved
So I have an app with a 2 different models, Comments and Replies, each of which you can either Agree or Disagree, so I have a polymorphic model called Emotion. Here is my code for these:
class Com...
Discourtesy asked 21/3, 2012 at 17:11
4
Solved
I am using PostgreSQL 9.5 (but upgrade is possible to say 9.6).
I have permissions table:
CREATE TABLE public.permissions
(
id integer NOT NULL DEFAULT nextval('permissions_id_seq'::regclass),
...
Banwell asked 16/5, 2017 at 21:28
1
I need some help with doctrine 2 that uses "polymorphic associations". Let me clarify myself. Entitys can support file attachments using a subset of the polymorphic relationship. the File entity is...
Dupin asked 21/3, 2017 at 12:7
5
Solved
I can eager load polymorphic relations/models without any n+1 issues. However, if I try to access a model related to the polymorphic model, the n+1 problem appears and I can't seem to find a fix. H...
Foothold asked 4/11, 2014 at 3:6
2
I have a table with a polymorphic reference that I generated via the following migration:
def change
add_reference :table_name, :thing, polymorphic: true, index: true
end
When I ran the migra...
Marquardt asked 13/2, 2017 at 20:38
1
Solved
I have the same exact schema as described here with a polymorphic join table: http://aaronvb.com/articles/a-polymorphic-join-table.html
class Location < ActiveRecord::Base
has_many :note_joins...
Flier asked 22/12, 2016 at 22:2
2
Solved
I am using a legacy database, so i do not have any control over the datamodel. They use a lot of polymorphic link/join-tables, like this
create table person(per_ident, name, ...)
create table per...
Shippen asked 30/12, 2009 at 13:55
6
Solved
I read this interesting article about Using Polymorphism to Make a Better Activity Feed in Rails.
We end up with something like
class Activity < ActiveRecord::Base
belongs_to :subject, polymo...
Ajmer asked 25/2, 2014 at 11:27
1
I'm trying to learn how to use polymorphic associations in my Rails 5 app. I recently asked this question, but I edited it so many times to show all the things I was trying, it has become messy
I ...
Armure asked 10/11, 2016 at 1:58
0
I'm trying to learn how to use polymorphic associations in my Rails 5 app.
I have models called Organisation, Proposal and Package::Bip.
The associations are:
Organisation
has_many :bips, as:...
Muns asked 6/11, 2016 at 22:12
1
Solved
I have a legacy database that has a few tables which were designed using Polymorphic Associations. By polymorphic associations, I mean that those tables can be child of different tables according t...
Cheka asked 8/7, 2016 at 21:0
2
Solved
Is it posible to validate the uniqueness of a child model's attribute scoped against a polymorphic relationship?
For example I have a model called field that belongs to fieldable:
class Field <...
Cart asked 31/3, 2010 at 21:27
1
I have this fixture:
resource:
name: my resource
owner: user_1 (User)
Resource is defined like this:
class Resource < ActiveRecord::Base
belongs_to :owner, :polymorphic => true
User ...
Hypertension asked 9/8, 2011 at 4:15
1
Solved
I'm trying to add an Evaluation model to my Rails 4 app.
I have made a model called evaluation.rb. It has:
class Evaluation < ActiveRecord::Base
belongs_to :evaluator, :polymorphic => tru...
Bevatron asked 4/4, 2016 at 4:16
2
Solved
A Person can have many Events and each Event can have one polymorphic Eventable record. How do I specify the relationship between the Person and the Eventable record?
Here are the models I have:
...
Crystallite asked 9/8, 2011 at 13:46
1
I am making an application with the mean.js boilerplate. It is a recruitment engine with users as employers and candidates. Now Employers and candidates should be stored as separate documents and e...
Bonar asked 3/7, 2014 at 18:45
2
Solved
I have few models in my Rails application, which are:
User
Photo
Album
Comment
I need to make comments belog to either to Photo or Album, and obviously always belong to User. I'm going to use p...
Carberry asked 27/1, 2016 at 12:14
© 2022 - 2024 — McMap. All rights reserved.