polymorphic-associations

Specify foreign key on one column and the value of another column

南笙酒味 提交于 2019-12-07 04:49:54
问题 I have a table ASSETS that has a structure as it is shown below : ---------------------------------------------------- ID (PK) | DESCRIPTION | TYPE | Do- | Do+ | Dx- | Dx+ ---------------------------------------------------- TYPE column has a foreign key , possible values are SECURITY or CURRENCY (i.e. FX ), also I have two more tables : CURRENCIES ( for example , EUR , RUB or USD ) : -------------------------------------------------------- ID (PK)| FROM (FK ASSETS.ID) | TO (FK ASSETS.ID) |

Many-to-many connection and Associations

牧云@^-^@ 提交于 2019-12-06 13:17:02
问题 A User can Upload a Clip via the Clips Scaffold , this clip either belongs to a Show and or an Album (Show Controller, Album Controller). A user can have ONLY ONE SHOW MANY ALBUMS What i'm trying to accomplish: A User can Upload Clips , these clips can be attached to either a Show or/and an Album For a more detailed overview take a look at the image below: Problem #1 What i'm not understanding is the associations i must use. My current Models: User Model : has_many :clips, dependent: :destroy

Laravel saving mass assignment with a morphMany relation

北慕城南 提交于 2019-12-06 10:01:24
I'm looking at mass assignment in Laravel, and trying to mass assign data for both one model and it's related model. My models: class News extends Eloquent { protected $table = 'news'; protected $fillable = array( 'title', 'slug', 'author', 'img', 'content', ); public function content() { return $this->morphMany('Content', 'morphable')->orderBy('section'); } } class Content extends Eloquent { protected $table = 'contents'; protected $fillable = array( 'rawText', 'section', ); public function morphable() { return $this->morphMany(); } } My Input I have Input:all() looking like this, coming from

Column family ID mismatch (found cebcc380-72d4-11e7-9a6b-bd620b945799; expected c05d6970-72d4-11e7-9a6b-bd620b945799)

Deadly 提交于 2019-12-06 07:34:27
How can i resolve this error Column family ID mismatch (found cebcc380-72d4-11e7-9a6b-bd620b945799; expected c05d6970-72d4-11e7-9a6b-bd620b945799) Caused by: java.util.concurrent.ExecutionException: org.apache.cassandra.exceptions.ConfigurationException: Column family ID mismatch (found cebcc380-72d4-11e7-9a6b-bd620b945799; expected c05d6970-72d4-11e7-9a6b-bd620b945799) at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[na:1.8.0_131] at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[na:1.8.0_131] at org.apache.cassandra.utils.FBUtilities.waitOnFuture(FBUtilities.java

How can I elegantly construct a form for a model that has a polymorphic association?

自闭症网瘾萝莉.ら 提交于 2019-12-06 04:34:13
问题 Here are my models: class Lesson < ActiveRecord::Base belongs_to :topic, :polymorphic => true validates_presence_of :topic_type, :topic_id end class Subject < ActiveRecord::Base has_many :lessons, :as => :topic end class Category < ActiveRecord::Base has_many :lessons, :as => :topic end Now, what I need is a form that will allow the user to create or update Lessons. The questions is, how can I provide a select menu that offers a mix of Subjects and Categories? (To the user, on this particular

polymorphic_path for custom collection route

时间秒杀一切 提交于 2019-12-06 02:04:56
问题 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 :documentable, :polymorphic => true end class User < ActiveRecord::Base has_many :documents, :as => :documentable end and controller structure: class DocumentsController < ApplicationController def index # not important end def filter # not important end end I can easily in a view say: polymorphic_path([@user,

Source Reflection Errors with has_many :through

我的梦境 提交于 2019-12-05 13:20:24
I'm attempting to create a system where my site's users can favorites pages. Those pages have two types, either clubs or sports. So, I have four models, associated as such: User Model: class User < ActiveRecord::Base .. has_many :favorites has_many :sports, :through => :favorites has_many :clubs, :through => :favorites .. end Favorites Model: class Favorite < ActiveRecord::Base .. belongs_to :user belongs_to :favoritable, :polymorphic => true end Club Model: class Club < ActiveRecord::Base .. has_many :favorites, :as => :favoritable has_many :users, :through => :favorites def to_param slug end

ActiveRecord::HasManyThroughAssociationPolymorphicSourceError

淺唱寂寞╮ 提交于 2019-12-05 08:09:44
I need a player to have many structures and the structure to belong to the player. Structure is a polymorphic relationship. class Player < ActiveRecord::Base has_many :player_structures has_many :structures, :through => player_structures end class PlayerStructures < ActiveRecord::Base belongs_to :structure, polymorphic: true belongs_to :player end class StructureA < ActiveRecord::Base has_one :player_structure, :as => :structure has_one :player, :through => :player_structure end class StructureB < ActiveRecord::Base has_one :player_structure, :as => :structure has_one :player, :through =>

Specify foreign key on one column and the value of another column

大憨熊 提交于 2019-12-05 07:03:06
I have a table ASSETS that has a structure as it is shown below : ---------------------------------------------------- ID (PK) | DESCRIPTION | TYPE | Do- | Do+ | Dx- | Dx+ ---------------------------------------------------- TYPE column has a foreign key , possible values are SECURITY or CURRENCY (i.e. FX ), also I have two more tables : CURRENCIES ( for example , EUR , RUB or USD ) : -------------------------------------------------------- ID (PK)| FROM (FK ASSETS.ID) | TO (FK ASSETS.ID) | VALUE -------------------------------------------------------- and SECURITIES ( for example , MTS , GAZP

rails joins polymorphic association

对着背影说爱祢 提交于 2019-12-05 05:17:59
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, :inverse_of => :notifiable, :dependent => :destroy end end end class Bill < ActiveRecord::Base include Notifiable end class Balance < ActiveRecord::Base include Notifiable end class Notification belongs_to :notifiable, :polymorphic => true belongs_to :bill, foreign_key: 'notifiable_id', conditions: "notifiable_type = 'Bill'" belongs_to :balance, foreign_key: 'notifiable_id', conditions: "notifiable_type =