polymorphic-associations Questions
2
I want a class to belong_to other classes through a polymorphic association.
What is the best way to restrict the association to a specific list of classes?
I am considering using a custom validati...
Immortelle asked 18/11, 2016 at 16:14
3
Solved
I am working on a database which has some types (e.g. User, Appointment, Task etc.) which can have zero or more Notes associated with each type.
The possible solutions I have come across for imple...
Hobbledehoy asked 23/6, 2019 at 19:8
7
Solved
I'm relatively new to Rails. I would like to add an association to a model that uses the polymorphic association, but returns only models of a particular type, e.g.:
class Note < ActiveRecord::...
Hamish asked 18/2, 2014 at 10:31
6
Solved
Using Ruby on Rails, how can I achieve a polymorphic has_many relationship where the owner is always of a known but the items in the association will be of some polymorphic (but homogenous) type, s...
Incomputable asked 9/7, 2010 at 2:3
14
Solved
My question is essentially the same as this one:
Polymorphic Association with multiple associations on the same model
However, the proposed/accepted solution does not work, as illustrated by a com...
Nealon asked 22/3, 2010 at 17:41
4
Solved
Folks,
Want to make sure I understand this correctly. And please disregard the case for inheritance here (SentientBeing), trying to instead focus on polymorphic models in has_many :through relatio...
Gokey asked 5/11, 2009 at 20:12
3
Solved
Why can you not have a foreign key in a polymorphic association, such as the one represented below as a Rails model?
class Comment < ActiveRecord::Base
belongs_to :commentable, :polymorphic =&...
Hyperbolic asked 28/5, 2009 at 17:32
2
Solved
Up front, I'm using:
Ruby 2.3.1
Rails 5
rspec-rails 3.5
I've set up a mountable Rails engine with a polymorphic model that I want to use in other engines. The model class looks like this:
mo...
Otiliaotina asked 15/11, 2016 at 16:36
10
How can I create a database seeder factory for the following configuration?
User
// create_users_table.php
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
......
Demise asked 10/3, 2018 at 4:47
4
Solved
Here's my Schema
class Menu < ActiveRecord::Base
belongs_to :menuable, :polymorphic => true
end
class Page < ActiveRecord::Base
has_one :menu, :as => :menuable
end
class Links <...
Visually asked 16/8, 2009 at 9:15
4
Solved
I have setup a role based access controll system with the following models:
Role (as STI),
UserRole (global roles)
ProjectRole (project specific roles)
Assignment (Polymorphic with different r...
Consequently asked 4/3, 2012 at 15:31
1
Solved
I have the following table structure as shown in the diagram:
Briefly, it is composed of several many-to-many polymorphic relationships as described:
many resources can have many sources and the ...
Cloudberry asked 21/6, 2021 at 19:37
2
I have following comments table in my app:
comments
--------
id INT
foreign_id INT
model TEXT
comment_text TEXT
...
the idea of this table is to store comments for various parts of my app - it c...
Daveta asked 4/1, 2010 at 23:12
3
I get the error
Cannot eagerly load the polymorphic association :messageable_fromuser
online = Message.all.joins(:messageable_fromuser)
I tried
online = Message.all.includes(:messageable_fromu...
Zerk asked 15/10, 2014 at 0:32
4
Solved
I'm trying to implement something similar to Ruby on Rails' polymorphic relationships.
I have the following three tables :
Events
Users
Organisations
An event can be owner by either a user or an ...
Fraxinella asked 25/2, 2010 at 11:13
8
Solved
I am using polymorphic associations to track Comments in my project. All very straight forward stuff.
The problem I have is in querying based on the polymorphic association and joining from the Co...
Nihi asked 25/3, 2009 at 3:37
7
Solved
I have a case of polymorphic association and STI here.
# app/models/car.rb
class Car < ActiveRecord::Base
belongs_to :borrowable, :polymorphic => true
end
# app/models/staff.rb
class Staff...
Allurement asked 9/3, 2012 at 3:41
3
Solved
I basically have two models (dog and cat) of the same type: pets. The table pets joins all dogs and cats in the database. Now I would like to be able to find a specific pet through the pet id in th...
Jabberwocky asked 12/7, 2018 at 10:55
2
Solved
I've got a pretty simple (I think) single-table inheritance (STI) setup in my Rails app.
There is a User model with a nested resource Post.
Using STI, I have it so that some Posts can be Post::Urg...
Shorts asked 24/10, 2015 at 1:25
5
Solved
Is there a way to find all Polymorphic models of a specific polymorphic type in Rails? So if I have Group, Event, and Project all with a declaration like:
has_many :assignments, :as => :assignable...
Wan asked 23/2, 2010 at 0:2
7
Solved
I have a polymorphic association (belongs_to :resource, polymorphic: true) where resource can be a variety of different models. To simplify the question assume it can be either a Order or a Custome...
Propitiatory asked 13/3, 2017 at 21:0
3
Solved
I have a model like this:
<?php
class Post extends Eloquent {
protected $fillable = [];
public function photos()
{
return $this->morphMany('Upload', 'imageable');
}
public function...
Courtly asked 3/2, 2015 at 17:55
3
Solved
I created a model for comments at the start of a project, but have now come to the realisation I need to create some polymorphic relations so I can use comments with a number of other models as wel...
Sowers asked 11/4, 2017 at 18:15
2
I have the following models in my app
class User < ActiveRecord::Base
has_many :articles
has_many :tour_companies
has_many :accomodations
end
class Articles < ActiveRecord::Base
belongs_to ...
Transept asked 5/3, 2014 at 6:55
9
I have tons of instances where I need to implement some sort of Polymorphic Association in my database. I always waste tons of time thinking through all the options all over again. Here are the 3 I...
Hasen asked 9/8, 2011 at 17:28
1 Next >
© 2022 - 2024 — McMap. All rights reserved.