polymorphic-associations

Polymorphic has_and_belongs_to_many

随声附和 提交于 2020-05-30 07:38:28
问题 How define a has_and_belongs_to_many polymorphic association? Situation: Figure that we have users, tracks, lists, etc... and all these models can be tagged and use this tag for filter. What i'm trying to do is: Use has_and_belongs_to_many that enable to a tag to have other objects, and that other objects also can have other tags. So for enable a tag that belongs to more than one kind of object (users or tracks or tracklists), we need to use polymorphic relations. That's my code on this

Route concern and polymorphic model: how to share controller and views?

僤鯓⒐⒋嵵緔 提交于 2020-01-30 18:48:47
问题 Given the routes: Example::Application.routes.draw do concern :commentable do resources :comments end resources :articles, concerns: :commentable resources :forums do resources :forum_topics, concerns: :commentable end end And the model: class Comment < ActiveRecord::Base belongs_to :commentable, polymorphic: true end When I edit or add a comment, I need to go back to the "commentable" object. I have the following issues, though: 1) The redirect_to in the comments_controller.rb would be

Rails: Polymorphic User Table a good idea with AuthLogic?

北战南征 提交于 2020-01-25 06:20:46
问题 I have a system where I need to login three user types: customers, companies, and vendors from one login form on the home page. I have created one User table that works according to AuthLogic's example app at http://github.com/binarylogic/authlogic_example. I have added a field called "User Type" that currently contains either 'Customer', 'Company', or 'Vendor'. Note: each user type contains many disparate fields so I'm not sure if Single Table Inheritance is the best way to go (would welcome

Devise polymorphic association nested attributes with simple form using rails 4

左心房为你撑大大i 提交于 2020-01-24 20:20:27
问题 I am making a polymorphic association with devise and simple for but for some reason i cant get the params to work here is my code: User: class User < ActiveRecord::Base devise :database_authenticatable, :rememberable, :trackable, :validatable belongs_to :loginable, polymorphic: true end Designer: class Designer < ActiveRecord::Base has_one :user, as: :loginable accepts_nested_attributes_for :user end Layout: <%= simple_form_for [:admin, @designer] , :html => { :class => 'form-horizontal' }

How to create follower relationships using Polymorphic Many to Many relationships with Laravel?

▼魔方 西西 提交于 2020-01-17 04:12:25
问题 Okay, so I'm trying to create a relationship where users can follow other users or follow categories. I got a recommendation to use Polomorpic Many to Many relationships. Right now I'm trying to create a follower - followee relationship but I can't wrap my head around how to set up the models and the controller. TABLES Users Schema::create('users', function (Blueprint $table) { $table->increments('id'); $table->string('email'); $table->string('password'); $table->string('first_name'); });

Rails 4 - post completion evaluations model - structure

天涯浪子 提交于 2020-01-17 01:22:49
问题 I'm still feeling my way with Rails. I'm trying to add an evaluation function to my projects based app. I want each project participant to submit an evaluation when a project is complete. I have an evaluation model with: Evaluation.rb # == Schema Information # # Table name: evaluations # # id :integer not null, primary key # user_id :integer # evaluatable_id :integer # evaluatable_type :string # overall_score :integer # project_score :integer # personal_score :integer # remark :text # work

Laravel-Many-to-one Polymorphic relationship

北战南征 提交于 2020-01-15 07:46:06
问题 I am using laravel 5.1. The scenario is as follows(this is an example. The real scenario is similar to this example) I have 3 models College Student Teacher A college can have many students but a student can belong to only 1 college. A college can have many teachers but a teacher can belong to only 1 college. I want to establish relationships between these tables in laravel. One of the methods for this is to place a college_id foreign key on the Students and Teachers table. But in my case,

Polymorphic cross-associations on Entity Framework

半腔热情 提交于 2020-01-14 11:12:58
问题 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