polymorphic-associations Questions
1
I have two models (Item and Theme). They are both owned by a third model Users with a has_many association (User has many Themes and Items). Both Item and Theme have_many :images.
The Image model ...
Umbelliferous asked 3/9, 2010 at 23:28
1
Solved
In my Rails 4 app, I have the following models:
User
has_many :administrations
has_many :calendars, through: :administrations
has_many :comments
has_many :calendar_comments, through: :calendars, :...
Leonidaleonidas asked 14/12, 2015 at 19:8
4
Solved
I would like set up a polymorphic relation with accepts_nested_attributes_for. Here is the code:
class Contact <ActiveRecord::Base
has_many :jobs, :as=>:client
end
class Job <ActiveReco...
Heptameter asked 19/10, 2010 at 13:48
1
Solved
I'm not new using Laravel but it's first time that I need/want to use polymorphic relations.
I saw a example at Laravel.com and it says that I should use 'imageable_id' to a table called 'images', ...
Urbanism asked 22/9, 2015 at 19:39
7
See comments for updates.
I've been struggling to get a clear and straight-forward answer on this one, I'm hoping this time I'll get it! :D
I definitely have a lot to learn still with Rails, howev...
Cymoid asked 14/7, 2009 at 22:1
2
Solved
I'm trying to setup a polymorphic one-to-one relationship (the polymorphic equivalent of has_one and belongs_to).I've got an Address model, and there are several other models that I want to have on...
Bosworth asked 25/2, 2014 at 11:29
0
I'm trying to optimize hibernate queries and faced the problem that hibernate makes more complicated queries than I expected.
I have a base class WorkUnit and several subclasses CheckEmployee, Mee...
Philcox asked 20/8, 2015 at 14:36
1
I am trying setup a select menu to associate a ImageGallery with a product. The ImageGallery is polymorphic since it is shared among a few models. Formtastic seems to be very confused about what to...
Arguelles asked 28/3, 2014 at 23:3
1
Solved
I try to create a polymorphic association, what is common in Rails but unfortunately not in Yii2. As part of the implementation I need to define the relation:
public function getImages()
{
retu...
Vocative asked 28/5, 2015 at 10:3
2
Solved
Given the routes:
Example::Application.routes.draw do
concern :commentable do
resources :comments
end
resources :articles, concerns: :commentable
resources :forums do
resources :forum_topi...
Roca asked 4/5, 2013 at 15:46
4
Solved
I have a table ASSETS that has a structure as it is shown below :
----------------------------------------------------
ID (PK) | DESCRIPTION | TYPE | Do- | Do+ | Dx- | Dx+
------------------------...
Puma asked 22/12, 2014 at 12:40
2
I have a ploymorphic association named Notifiable in a model named Notifiaction:
module Notifiable
def self.included(base)
base.instance_eval do
has_many :notifications, :as => :notifiable, ...
Inexpungible asked 19/8, 2014 at 18:21
2
Solved
I have the following route definition:
resources :documents do
collection do
post :filter
end
end
and the following model structure:
class Document < ActiveRecord::Base
belongs_to :docum...
Coincidentally asked 26/5, 2011 at 16:37
1
I'm trying to figure out what to name a polymorphic association and not coming up with good options. The class that will contain the polymorphic association is called LicenseBatch, and if it weren'...
Osteoid asked 12/8, 2014 at 21:10
3
Let's say we have these models
class Message
belongs_to :messageable, polymorphic: true
end
class Ticket
has_many :messages, as: :messageable
has_many :comments
end
class User
has_many :mess...
Bracknell asked 26/2, 2013 at 18:8
2
Solved
After upgrading from Rails 3.2 to 4.1, the following code which used to work is now failing:
in a controller/spec:
post = user.posts.build
post.contacts << contact # contact is a persisted ...
Megan asked 25/5, 2014 at 12:40
1
Solved
I have an Org model and a Tag model. I want to associate tags with organizations. My database tables and Eloquent models are set up like so ...
org
id - integer
name - string
...
tags
id - in...
Tow asked 27/5, 2014 at 18:1
2
Solved
I have a metric table that I expect to be very large. It has a polymorphic association so that it can belongs_to other models that want to record some metric. I typically index association columns ...
Algiers asked 21/10, 2010 at 4:9
1
Solved
I try to implement polymorphic association by mean of SQLAlchemy library and use for it the example:
discriminator_on_association.
But there is one incompatibility with my case. In the example:...
Consumable asked 24/3, 2014 at 6:42
1
Solved
I have an Audit class which is used to store action, by and on attributes.
class Audit < ActiveRecord::Base
attr_accessible :activity
belongs_to :by, :polymorphic => true
belongs_to :on, ...
Launcelot asked 25/11, 2012 at 21:16
2
Solved
For some reason the source type for a polymorphic has_many :through association is always 0, despite having set a :source_type.
Here's what my models look like...
Foo:
has_many :tagged_items, :a...
Bushman asked 27/2, 2014 at 11:59
1
Solved
We are trying to add multiple favoritable objects, where a user can favorite many different objects, but are not sure how to make it work.
Here is the Favorite model:
class Favorite < ActiveR...
Cauca asked 16/2, 2014 at 21:37
1
Solved
I'm writing RSpec code for polymorphic associations. I have two testing ideas that
Use Factory Girl to build polymorphic associations
Use rails methods to build polymorphic associations.
Here...
Shiah asked 13/2, 2014 at 8:25
1
Solved
I have been trying to find this one link for hours now. I have a polymorphic association where both collections & assortments have designs.
Collection model
has_many :designs, :as => :tar...
Verile asked 17/12, 2013 at 1:23
4
Solved
I have a table Foo that has a polymorphic belongs_to association called bar. The foos table has the standard bar_id column. However, instead of a string-based bar_type column, I have an integer bar...
Get asked 25/5, 2011 at 21:40
© 2022 - 2024 — McMap. All rights reserved.