FAQ Database Discussion Community


Rails STI vs Polymorphic vs Neither

ruby-on-rails,polymorphism,polymorphic-associations,single-table-inheritance,sti
I have a Users class in my rails app. I need two types of users, 1) Players, 2) Managers. Users will all log in using Devise and have same basic user fields. I will have a League model. What is the best way to model this? STI doesn't seem quite...

Laravel polymorphic relationship

laravel-4,polymorphic-associations
I have different Database tables and below is the DB Diagram. I am trying to make a many to many polymorphic relationship, but no luck, Please guide me that what i need to do, means where i need to add which type relationship/code? ...

JSON Expectations for Ember Data Polymorphic Relationships

json,ember-data,polymorphic-associations
DEBUG: Ember : 1.8.1 ember.js:15373DEBUG: Ember Data : 1.0.0-beta.18 ember.js:15373DEBUG: Handlebars : 1.3.0 ember.js:15373DEBUG: jQuery : 1.11.3 So I have a "Request" model which can depend on an account or other Requests that stand in for and account when it is fulfilled. I'm a bit confused about how to get...

What is wrong with this polymorphic association?

ruby,ruby-on-rails-4,associations,polymorphic-associations
I have class User::AuthInfo < ActiveRecord::Base self.table_name = "auth_infos" belongs_to :authenticable, polymorphic: true end and class User::Customer < ActiveRecord::Base self.table_name = "customers" has_one :auth_info, as: :authenticable end I am expecting that by doing this: User::Customer.last.auth_info the output should be a record from auth_info. But I see the query is wrong:...

How to set a notification conditional based on polymorphic comments?

ruby-on-rails,ruby,notifications,comments,polymorphic-associations
I have this in comment.rb: def create_notification self.notifications.create( comment: self, goal: self.goal, valuation: self.valuation, user: # How to fix this line? if valuation self.valuation.user, else goal self.goal.user, end read: false ) end How can we make it where when the comment is on a valuation the notification uses user: self.valuation.user...

polymorphic association belongs to User

ruby-on-rails,model-view-controller,rails-activerecord,polymorphic-associations
I have a comments model which is a polymorphic association which is involved with Statuses and Photos. How can I create this polymorphic association to also belong to a User so that when a user creates a comment under statuses or photos it will also recieve the current_user id? this...

Has many association on tagging user in a post

ruby-on-rails,ruby,ruby-on-rails-4,has-many-through,polymorphic-associations
In my app a User can Post something to his timeline and Tag other's users in his post (something like facebook). In my model I have to know who was tagged in which post and who did tag (always the post's owner). I've found something similar here with hashtags model,...

Ruby on Rails 3 Multiple Associations

ruby-on-rails,ruby-on-rails-3,associations,polymorphic-associations
I have the following associations in place: class User < ActiveRecord::Base has_many :shopping_requests has_many :recommendations, :through => :shopping_requests end class ShoppingRequest < ActiveRecord::Base belongs_to :user has_many :recommendations end class Recommendation < ActiveRecord::Base belongs_to :shopping_request has_one :user, :through => :shopping_requests end Now I need to add a Compliment class. A user...

How to remove a polymorphic relation in Eloquent?

php,laravel,eloquent,polymorphic-associations
I have a model like this: <?php class Post extends Eloquent { protected $fillable = []; public function photos() { return $this->morphMany('Upload', 'imageable'); } public function attachments() { return $this->morphMany('Upload', 'attachable'); } } and my morphMany table's schema is like this: CREATE TABLE `uploads` ( `id` int(10) unsigned NOT NULL...