Questions tagged [has-many-polymorphs]

This tag is for questions about the Rails has-many-polymorphs plugin.

The title is oxymoronic.

42 questions
27
votes
2 answers

HABTM Polymorphic Relationship

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…
7
votes
1 answer

has_many :through, :source, :source_type returning empty array

I got some Manager and SoccerTeam model. A manager "owns" many soccer teams; also a manager can comment on soccer teams and can comment on other managers too: manager.rb # Soccer teams the manager owns has_many :soccer_teams, :dependent =>…
7
votes
1 answer

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

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,…
Jens
  • 1,386
  • 14
  • 31
5
votes
1 answer

Rails Has Many Through Polymorphic Checkboxes

This one's really getting me down! :( I'm trying to make a nested model form for my User model with a checkbox list in it where multiple Stores can be checked or unchecked to administer the Stores through model Staffing. class Staffing <…
3
votes
1 answer

Separate Polymorphic Association table

After reading the Ruby on Rails guides and a few of the stackoverflow responses to questions about polymorphic association I understand its use and implementation but I have a question about a specific use scenario. I have tags that can be…
3
votes
1 answer

Conflicting associations in has_many_polymorphs

I'm using has_many_polymorphs to create a "Favorites" feature on a site where multiple users can post stories and make comments. I want users to be able to "favorite" stories and comments. class User < ActiveRecord::Base has_many :stories has_many…
2
votes
1 answer

Rails self-referential has_many through

I'm trying to make a self-referential user class with three basic user types - parent, student, and tutor. A student belongs to a parent and can also belong to a tutor. Of course, the way I have it written, rails only recognizes the parent having…
2
votes
0 answers

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

My product model like this : morphMany(Favorite::class, 'favoritable'); …
moses toh
  • 12,344
  • 71
  • 243
  • 443
2
votes
1 answer

What does has_many_polymorphs mean by "Referential integrity violation"?

I have a has_many_polymorphs relationship between a Candidate and many events of various type. In particular, a Candidate creates a Created event when it is created. class Candidate < ActiveRecord::Base has_many_polymorphs :events, :through =>…
James A. Rosen
  • 64,193
  • 61
  • 179
  • 261
1
vote
2 answers

accessing an attr_writer on a nested attribute asset from a file uploaded via form

I have the following model structure class Asset < ActiveRecord::Base attr_writer :session_user_id ... end class Item < ActiveRecord::Base has_many :assets, :as => :assetable, :dependent => :destroy ... end and want to put the user_id in…
timpone
  • 19,235
  • 36
  • 121
  • 211
1
vote
1 answer

Rails combine multiple polymorphic has_many associations

I have a model called Organization that has many teams and has many collaborations. A Collaboration also has many teams. So the team model has a polymorphic association with Organization and Collaboration. What I would like to do is…
Asdrubal
  • 2,421
  • 4
  • 29
  • 37
1
vote
1 answer

Is it possible to define a polymorphic relationship through different paths (intermediate model) in Laravel models?

I have the models "Payment", "Estimate" and "Quote", a payment has a polymorphic relationship where it can belong either to a quote or to an estimate, simultaneously a quote can have many estimates, so an estimate is always going to belong to a…
1
vote
1 answer

has_many through and polymorphic relationships

I don't know if this is possible, but here goes: FruitBasket has_many :apples has_many :bananas ######## What to put here to access Worm through its pest_holder relationship? Apple has_many :worms, :as => :pest_holder belongs_to…
1
vote
2 answers

rails3 model question

i moved from php to rails3, and i still think it was a good decision! Anyway I have some models: users questions answers question_id votes user_id answer_id model for users: has_many :questions has_many :votes model for questions: belongs_to…
1
vote
0 answers

has_many through polymorphic with alias on both sides

I have a problem joining two models in a n..n association. I have the following associations in the context: Proposal n..n Product Proposal n..n Project Proposal n..n NewProject And similarly with this, I have: Order n..n Product Order n..n…
1
2 3