polymorphic-associations

Polymorphic cross-associations on Entity Framework

依然范特西╮ 提交于 2020-01-14 11:07:38
问题 OK, this is an interesting and most importably real urgent problem for me to solve... In order for others to neatly comprehend it, I've stretched myself to make a well illustrated post. The Object Model So I have this simple, easy and "beautiful" model in mind. See the first picture. (You can ignore PathEntry , it's not relevant in my situation.) The idea is that a MediaFeedItem owns: a collection of ThumbnailFileEntries (accesible through the ThumbnailFiles property) at most 1 raw FileEntry

Polymorphic cross-associations on Entity Framework

喜夏-厌秋 提交于 2020-01-14 11:07:28
问题 OK, this is an interesting and most importably real urgent problem for me to solve... In order for others to neatly comprehend it, I've stretched myself to make a well illustrated post. The Object Model So I have this simple, easy and "beautiful" model in mind. See the first picture. (You can ignore PathEntry , it's not relevant in my situation.) The idea is that a MediaFeedItem owns: a collection of ThumbnailFileEntries (accesible through the ThumbnailFiles property) at most 1 raw FileEntry

MYSQL join tables based on column data and table name

给你一囗甜甜゛ 提交于 2020-01-12 05:16:29
问题 I'm wondering if this its even posible. I want to join 2 tables based on the data of table 1. Example table 1 has column food with its data beeing "hotdog". And I have a table called hotdog. IS it possible to do a JOIN like. SELECT * FROM table1 t join t.food on id = foodid I know it doesnt work but, its even posible, is there a work arround?. Thanks in advance. 回答1: No, you can't join to a different table per row in table1 , not even with dynamic SQL as @Cade Roux suggests. You could join to

Polymorphic Association with multiple associations on the same model

好久不见. 提交于 2020-01-10 08:26:04
问题 I'm slightly confused about a polymorphic association I've got. I need an Article model to have a header image, and many images, but I want to have a single Image model. To make matters even more confusing, the Image model is polymorphic (to allow other resources to have many images). I'm using this association in my Article model: class Article < ActiveRecord::Base has_one :header_image, :as => :imageable has_many :images, :as => :imageable end Is this possible? Thanks. 回答1: Yep. That's

Rails 4 - Polymorphic associations

 ̄綄美尐妖づ 提交于 2020-01-06 03:27:06
问题 I am trying to make an app in Rails 4. I have a profile model and an address model. the Associations are: profile.rb has_many :addresses, as: :addressable address.rb belongs_to :addressable, :polymorphic => true Address is a polymorphic model. I have an address form which has: <%= simple_form_for(@address) do |f| %> <%= f.error_notification %> <div class="form-inputs"> <div class="row"> <div class="col-xs-3"> <%= f.input :unit %> </div> <div class="col-xs-3 col-xs-offset-1"> <%= f.input

Polymorphic Comments with Ancestry Problems

烈酒焚心 提交于 2020-01-06 01:59:25
问题 I am trying to roll together two Railscasts: http://railscasts.com/episodes/262-trees-with-ancestry and http://railscasts.com/episodes/154-polymorphic-association on my app. My Models: class Location < ActiveRecord::Base has_many :comments, :as => :commentable, :dependent => :destroy end class Comment < ActiveRecord::Base belongs_to :commentable, :polymorphic => true end My Controllers: class LocationsController < ApplicationController def show @location = Location.find(params[:id]) @comments

has_one/has_many with dependent destroy but using a different name for the key

岁酱吖の 提交于 2020-01-05 11:59:13
问题 So I'm looking at someone's code which has the following (paraphrased): class user has_one :connection, :dependent => :destroy has_one :second_user, :through => :connection, :class_name => 'User' end class connection belongs_to :user belongs_to :second_user, :class => 'User' end If I have a connection object and delete the associated 'user' it can be destroyed fine. But I also want to make it so that if the User occupying the 'second_user' field is destroyed the connection is destroyed. How

Evaluation - polymorphic associations on feedback loop

梦想的初衷 提交于 2020-01-05 04:09:10
问题 I'm trying to figure out how to implement an evaluation model in my Rails 4 app. I've previously asked these related questions but am yet to solve this problem: Rails 4 Polymorphic associations and concerns Rails 4 - post completion evaluations model - structure I have: class Evaluation < ActiveRecord::Base belongs_to :evaluator, :polymorphic => true belongs_to :evaluatable, :polymorphic => true I have also made concerns for evaluator and evaluatable as: module Evaluator extend ActiveSupport:

searching multiple polymorphic items using thinking sphinx

最后都变了- 提交于 2020-01-05 02:35:26
问题 I have an attachments table that has multiple values (via polymorphic assoc). I'd like to be able to search for multiple values (like an AND in SQL) via thinking-sphinx. For example: class FieldValue < ActiveRecord::Base belongs_to :customized, :polymorphic => true end class Attachment < ActiveRecord::Base has_many :field_values, :as => :customized, :dependent => :destroy define_index do has field_values.field_id, :as => :field_ids, :type => :multi indexes field_values.value, :as => :field

ActiveRecord builds instance of wrong class through a scope targeting an STI class

强颜欢笑 提交于 2020-01-04 06:44:17
问题 I would like to be able to call the build method on a scope that targets a certain class of model via its STI type, and have ActiveRecord build an instance of the correct class. class LineItem < ActiveRecord::Base scope :discount, where(type: 'DiscountLineItem') end class DiscountLineItem < LineItem; end > LineItem.discount.build # Expect an instance of DiscountLineItem here => #<LineItem ...> Here, I expected an instance of DiscountLineItem , not an instance of LineItem . 回答1: Even though