If anybody on edge familiar with this could help, that would be "great" :) I have different types of things I want to be "reviewable". So, instead of having a slew of HABTM... this new Polymorphic Associations schtick seemed like the best solution. I have everything setup as I thought it should be (so I think)... but it doesn''t appear to be working correctly. Here is my setup: User (table Clients: basic user stuff belonging to a functional STI relationship) =========def User < Client has_many :reviewings, :as => :reviewable, :dependent => true has_many :reviews, :through => :reviewings end ========= Review (table Reviews: id, rating, review) =========def Review < AR:B has_many :reviewings end ========= Reviewing (table Reviewings: id, review_id, reviewable_id, reviewable_type) =========def Reviewing < AR:B belongs_to :review belongs_to :reviewable, :polymorphic => true end ========= Now, within console: ==========>> u = User.find(:first) my user stuff>> r = Review.find(:first)my review stuff>> u.reviews << radded r to u''s reviews I check the "reviews" table, and the review is successfully entered... however, there is no entry in "reviewables". I''ve played around with this for quite a while trying to debug why an insert isn''t happening into this table, but no dice. Any insight into this would be greatly appreciated ! =Dylan -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060209/81847a45/attachment.html
On 2/8/06, Dylan Stamat <dylans@gmail.com> wrote:> If anybody on edge familiar with this could help, that would be "great" :) > > I have different types of things I want to be "reviewable". So, instead of > having a slew of HABTM... this new Polymorphic Associations schtick seemed > like the best solution. I have everything setup as I thought it should be > (so I think)... but it doesn''t appear to be working correctly. Here is my > setup: > > > User (table Clients: basic user stuff belonging to a functional STI > relationship) > =========> def User < Client > has_many :reviewings, :as => :reviewable, :dependent => true > has_many :reviews, :through => :reviewings > end > =========> > Review (table Reviews: id, rating, review) > =========> def Review < AR:B > has_many :reviewings > end > =========> > Reviewing (table Reviewings: id, review_id, reviewable_id, > reviewable_type) > =========> def Reviewing < AR:B > belongs_to :review > belongs_to :reviewable, :polymorphic => true > end > =========> > > Now, within console: > ==========> >> u = User.find(:first) > my user stuff > >> r = Review.find(:first) > my review stuff > >> u.reviews << r > added r to u''s reviews > > I check the "reviews" table, and the review is successfully entered... > however, there is no entry in "reviewables". > I''ve played around with this for quite a while trying to debug why an insert > isn''t happening into this table, but no dice. > > Any insight into this would be greatly appreciated ! > => Dylando you have a reviewable_id and reviewable_type field? polymorphic joins are like backwards STI classes... -- Rick Olson http://techno-weenie.net
Yup ! It''s in the "reviewings" table. (note the column names next to the class definitions in my first email.) On 2/8/06, Rick Olson <technoweenie@gmail.com> wrote:> > On 2/8/06, Dylan Stamat <dylans@gmail.com> wrote: > > If anybody on edge familiar with this could help, that would be "great" > :) > > > > I have different types of things I want to be "reviewable". So, instead > of > > having a slew of HABTM... this new Polymorphic Associations schtick > seemed > > like the best solution. I have everything setup as I thought it should > be > > (so I think)... but it doesn''t appear to be working correctly. Here is > my > > setup: > > > > > > User (table Clients: basic user stuff belonging to a functional > STI > > relationship) > > =========> > def User < Client > > has_many :reviewings, :as => :reviewable, :dependent => true > > has_many :reviews, :through => :reviewings > > end > > =========> > > > Review (table Reviews: id, rating, review) > > =========> > def Review < AR:B > > has_many :reviewings > > end > > =========> > > > Reviewing (table Reviewings: id, review_id, reviewable_id, > > reviewable_type) > > =========> > def Reviewing < AR:B > > belongs_to :review > > belongs_to :reviewable, :polymorphic => true > > end > > =========> > > > > > Now, within console: > > ==========> > >> u = User.find(:first) > > my user stuff > > >> r = Review.find(:first) > > my review stuff > > >> u.reviews << r > > added r to u''s reviews > > > > I check the "reviews" table, and the review is successfully entered... > > however, there is no entry in "reviewables". > > I''ve played around with this for quite a while trying to debug why an > insert > > isn''t happening into this table, but no dice. > > > > Any insight into this would be greatly appreciated ! > > => > Dylan > > do you have a reviewable_id and reviewable_type field? polymorphic > joins are like backwards STI classes... > > -- > Rick Olson > http://techno-weenie.net > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060209/bbaab23a/attachment.html