polymorphic-associations

How can I resolve a three-way polymorphic association?

半城伤御伤魂 提交于 2020-01-01 10:58:31
问题 First let me say I am using MySQL (not transactional) and that this can't be changed. Also, I have simplified the tables here for brevity and clarity. In this example a 'Lesson' is comprised of it's internal attributes and an external attributes with it's own attributes 'Readings'. 'Readings' has it's own key dependent attributes and three distinct external attributes (the reading sources). I want to avoid the polymorphic association that arrises here but am unable to wrap my head around it.

How can I resolve a three-way polymorphic association?

三世轮回 提交于 2020-01-01 10:58:11
问题 First let me say I am using MySQL (not transactional) and that this can't be changed. Also, I have simplified the tables here for brevity and clarity. In this example a 'Lesson' is comprised of it's internal attributes and an external attributes with it's own attributes 'Readings'. 'Readings' has it's own key dependent attributes and three distinct external attributes (the reading sources). I want to avoid the polymorphic association that arrises here but am unable to wrap my head around it.

Should I joint-index an ActiveRecord polymorphic association?

限于喜欢 提交于 2020-01-01 04:37:11
问题 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 like this to speed up association loading. I've heard people talking about joint-indexing this association. This looks like: add_index :comments, [:commentable_type, :commentable_id] But I've also heard counsel against creating indexes of low-cardinality, because the payoff of the index doesn't

Database best practices

怎甘沉沦 提交于 2020-01-01 03:11:55
问题 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 both user_id and profile_id fields, so if a user submits a comment, it gives the user_id leaves the profile_id blank is this right, wrong, is there a better way? 回答1: In the past I have used a centralized comments table and had a field for the fk_table it is referencing. eg: comments(id,fk_id,fk

MySQL foreign key using more than one field to reference to a primary key from another table

旧巷老猫 提交于 2019-12-25 17:45:03
问题 I want to reference 2 of my columns in one table to a primary key from another table. Here is how it looks like in the db structure: Users uid (INT) name (VARCHAR) 1 John Doe 2 Jane Doe SystemProcesses uid (INT) name (VARCHAR) 1 Hitman 2 Cron Logs uid (INT) modelType (VARCHAR) modelUID (INT) Action 1 Users 2 Jane Doe did this 2 Users 1 John Doe did that 3 SystemProcesses 1 Hitman just killed John Doe How do I reference modelType and modelUID in Logs table to those Users and SystemProcesses?

How to I serve data from an object's associations in rails forms?

你离开我真会死。 提交于 2019-12-25 07:48:28
问题 I have an object that I am developing a controller for that has many attributes. However, due to the data model I have created, most of the attributes that I have to edit are saved through associations in other tables. EG: I have articles that have tags through a taggings table (and about 20 other attributes saved in other tables). THe article has many other attributes through polymorphic associations etc.. The associations work great, and enable the saving of multiple entries of each

Rails, Polymorphic Association - rendering associated instances only

只谈情不闲聊 提交于 2019-12-25 04:13:50
问题 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: :ipable, class_name: Package::Bip accepts_nested_attributes_for :bips, reject_if: :all_blank, allow_destroy: true Proposal has_many :bips, as: :ipable, class_name: Package::Bip accepts_nested_attributes_for :bips, reject_if: :all_blank, allow_destroy: true Package::Bip belongs_to :ipable, :polymorphic =>

How to test Controllers under different namespaces and why this test fails?

折月煮酒 提交于 2019-12-24 05:53:16
问题 Dear fellow Overflowers, I am using Rails 2.3 and I have created a polymorphic Controller which is accessed by Views belonging to different namespaces. Here is the story and thanks for reading it in advance: I have these routes: rake routes | grep appointment new_patient_appointments GET /patients/:patient_id/appointments/new(.:format) {:controller=>"appointments", :action=>"new"} edit_patient_appointments GET /patients/:patient_id/appointments/edit(.:format) {:controller=>"appointments",

rails has_many manager

﹥>﹥吖頭↗ 提交于 2019-12-24 05:47:13
问题 I'm attempting to create a polymorphic imaging system which would allow various objects to have a cover image and additional images. Would I be correct in creating an Image model with belongs_to :imageable ? Or, should I separate out my logic so each model that will inherit image capabilities be given a separate polymorphic associations for both cover images and additional images? Then, once I have setup has_many relationship, how do I manage it? In a perfect world I would want to be able to

Rails - Displaying associated attributes - unpermitted parameters

早过忘川 提交于 2019-12-24 00:42:40
问题 I am trying to make an app in Rails 4. I have a profile model, a qualification model, and a vision model. The associations are: profile.rb has_many :qualifications accepts_nested_attributes_for :qualification has_one :vision accepts_nested_attributes_for :vision qualification.rb belongs_to :profile vision.rb belongs_to :profile I have several other models in a similar construct as qualification and vision (ie. they belong to profile). All relevant attributes have been included in the strong