has-many-polymorphs

How can I add, delete and get a favorite from product with polymorphic relationship, in Laravel 5.6?

只愿长相守 提交于 2020-01-21 20:09:08
问题 My product model like this : <?php ... class Product extends Model { ... protected $fillable = ['name','photo','description',...]; public function favorites(){ return $this->morphMany(Favorite::class, 'favoritable'); } } My favorite model like this : <?php ... class Favorite extends Model { ... protected $fillable = ['user_id', 'favoritable_id', 'favoritable_type']; public function favoritable() { return $this->morphTo(); } } My eloquent query laravel to add, delete and get like this : public

How to set up these CRUD controller actions for has_many_polymorphs and an error

梦想与她 提交于 2019-12-20 07:19:16
问题 I'm using the has_many_polymorphs plugin so that videos, topics, and users can be posted to profiles. Therefore, a profile has many "showable_objects" which can be videos, topics, and users. Also, the user who creates the "showable_object" will also be associated with it. I've already set up the model associations (below). The way I want a showable_object to be created is for a user to select another user from an autocomplete field on the show page of the resource. Then that resource is

HABTM Polymorphic Relationship

痞子三分冷 提交于 2019-12-17 09:32:49
问题 I'm pretty new to Rails, and i'm trying to do a polymorphic HABTM relationship. The problem is that I have three models that I want to relate. The first one is the Event model and then are two kind of attendees: Users and Contacts. What I want to do is to be able to relate as an attendee both users and contacts. So, what i have right now in my code is: Event Model has_and_belongs_to_many :attendees, :polymorphic => true User Model has_and_belongs_to_many :events, :as => :attendees Contact

Ruby on Rails 3: Combine results from multiple has_many or has_many_through associations

可紊 提交于 2019-12-07 03:40:17
问题 I have the following models. Users have UserActions, and one possible UserAction can be a ContactAction (UserAction is a polymorphism). There are other actions like LoginAction etc. So class User < AR::Base has_many :contact_requests, :class_name => "ContactAction" has_many :user_actions has_many_polymorphs :user_actionables, :from => [:contact_actions, ...], :through => :user_actions end class UserAction < AR::Base belongs_to :user belongs_to :user_actionable, :polymorphic => true end class

How to set up these CRUD controller actions for has_many_polymorphs and an error

无人久伴 提交于 2019-12-02 11:42:33
I'm using the has_many_polymorphs plugin so that videos, topics, and users can be posted to profiles. Therefore, a profile has many "showable_objects" which can be videos, topics, and users. Also, the user who creates the "showable_object" will also be associated with it. I've already set up the model associations (below). The way I want a showable_object to be created is for a user to select another user from an autocomplete field on the show page of the resource. Then that resource is associated with the profile of the selected user. My question is how should I be setting up my showable

HABTM Polymorphic Relationship

穿精又带淫゛_ 提交于 2019-11-27 07:49:09
I'm pretty new to Rails, and i'm trying to do a polymorphic HABTM relationship. The problem is that I have three models that I want to relate. The first one is the Event model and then are two kind of attendees: Users and Contacts. What I want to do is to be able to relate as an attendee both users and contacts. So, what i have right now in my code is: Event Model has_and_belongs_to_many :attendees, :polymorphic => true User Model has_and_belongs_to_many :events, :as => :attendees Contact Model has_and_belongs_to_may :events, :as => :attendees How the HABTM table migration needs to be? I'm a