Displaying 20 results from an estimated 2000 matches similar to: "Polymorphic Associations and grouping users and projects"
2006 Jul 26
3
Polymorphic Association with Single Table Inheritance?
Hello,
is it possible to setup a model/table schema like this:
Groupable --> Membership <-- Group
^ ^
| |
User UserGroup
I tried the following but failed:
Groupable (table with ''type'' column)
has_many :memberships, :as => :groupable
has_many :groups, :through => :memberships
2006 Aug 16
1
Naming rights_roles join model using has_many :through and polymorphic associations
Hi.
I have a couple of best practices questions regarding polymorphic
associations, naming join tables and user permissions.
Currently I have implemented the user authentication model from the
rails recipes book. Basically it goes something like this:
MODEL CLASSES:
class User < ActiveRecord::Base
has_and_belongs_to_many :roles
end
class Role < ActiveRecord::Base
2006 Sep 03
7
using polymorphic associations with acts_as_list
This is what I have
class Photo < ActiveRecord::Base
belongs_to :image, :polymorphic => true
acts_as_list :scope => image
end
class Place < ActiveRecord::Base
has_many :photos, :as => :image
end
class Child < ActiveRecord::Base
has_many :photos, :as => :image
end
I want to be able to reorder the images. What I need is for the
position of the photos to be set
2006 May 20
7
Polymorphic, many-to-many, self-referential data model
No matter what I try I''ve been unable to work how to get this to work with
the cool ActiveRecord helpers. I''m not sure if it''s possible, Josh Susser''s
blog suggests it is, but damned if I can work it out...
I have:
Container which can contain one or more Element. An Element is a polymorph
of either a Container or a Chunk. An Element can exist in one or more
2006 Nov 04
0
RESTful controller naming conventions
It is my understanding that originally controller names where singular.
In all the examples of RESTful controllers the names have been
pluralized.
So what is the new convention? Singular or plural controller names?
Leevi Graham
Front End Developer - User Interface Designer
www.leevigraham.com | Skype Me: leevi_graham
MSN Messenger: info@leevigraham.com
Download My VCard
--------------
2011 May 03
2
Database performance for polymorphic associations under high load
Hey guys,
I''ve been thinking lately about polymorphic associations, and I
wonder: is there a noticeable or tangible performance "hit" from doing
polymorphic associations when you''ve got your database under really
high query load?
So for example, maybe I have a "message" model, a "user" model and an
"administrator" model, without any
2006 Jul 26
1
Polymorphic Associations: dynamic finders
Is there any sort of dynamic finder for polymorphic associations?
For example if I had:
class InviteNode < ActiveRecord::Base
belongs_to :inviteable, :polymorphic => true
end
I would like to be able to search by:
InviteNode.find_by_inviteable(some_object)
instead of having to do:
InviteNode.find_by_inviteable_id_and_inviteable_type(some_object.id,
some_object.class.name)
obviously I
2006 Mar 31
2
Eager loading of polymorphic associations
Polymorphic associations work great until I try to do some eager
loading through :include. In my example, the interface name is
":imagehaver". Here''s my little eagerly loading find line:
Image.find(params[:id], :include => :imagehaver)
All it gives me is an ActiveRecord::EagerLoadPolymorphicError with no
further explanation. I haven''t been able to dig up anything
2008 Apr 11
1
polymorphic associations wrong when used with inherited class?
Consider the following:
class Event
belongs_to :event_object, :polymorphic => true
end
class Asset < ActiveRecord::Base
end
class EventedAsset < Asset
has_one :event, :as => :event_object
end
EventedAsset.find(:first).event generates the following SQL:
SELECT * FROM `events` WHERE (events.event_object_id = 1 AND
events.event_object_type = ''Asset'') LIMIT 1
2006 Feb 10
3
[Req] polymorphic associations howto
Hi people,
I''m looking into polymorphic associations as a way to cleanup some
messy parts of my code. I think they will allow me to do exectly what
I need, but since there''s little to none written on this subject, I''d be
delighted if someone could shed some light on this. Especially what
the different options and needed table structures need to be.
Thanks,
-
2007 Jan 27
1
Polymorphic Associations or not
Hey,
I am starting my store application again for the 3rd time, I am just
trying to get eveything right so that I don''t come up with any more
complex problems later. Hopefully someone can steer me in the right
direction.
I have a store that sells lots of types of product.
e.g. CDs, T-Shirts, DVD
Each product type has different associations.
Cds - multiple artists, multiple genres,
2006 May 18
0
Sorting Polymorphic Associations
Recently, I converted a single table inheritance design over to
polymorphic associations as that made a lot more sense from a database
perspective. One of the features of the ui, a drag and dropable list of
items, needs to be completely reworked though.
Instead of having one table with a "sort" column, I have 1 polymorphic
table "items" acting as a pointer to 3 or 4 other
2008 Jan 04
1
eager loading and polymorphic associations
There is a dedicated section about eager loading in the docs. A
coworker discovered eager loading does not work in polymorphic
associations the hard way :-) so I''ve written a patch that documents it:
http://dev.rubyonrails.org/ticket/10610
There are at least a couple of tickets that implement something that
would change that though:
http://dev.rubyonrails.org/ticket/9640
2008 Jun 13
1
Polymorphic :through associations
Could someone please help me with this association scheme? I am
familiar with habtm as well as the :through association but this one
has me stumped.
Here is an example DB.
Tags Table:
-------------------------
id
name
Taggables Table:
--------------------------
id
tag_id
taggble_type
taggable_id
For purposes of this example say that there are 2 other tables that
can be tagged and their model
2007 Oct 27
0
STI vs Polymorphic Associations
I have a MasterEvent model. It has attributes that is required by
another model Event. The user selects the MasterEvent model and I
create the Event model by merging the attributes of the selected
MasterEvent with the attributes that were presented for the Event
model in the form.
I have association declarations in the MasterEvent and Event models.
If I use STI does the subclasses inherit the
2006 Sep 17
0
[RFC] Nested Restful Resources + Polymorphic Associations
hi,
how to handle the problem addressed in this thread:
http://rails.techno-weenie.net/question/2006/9/6/nested-restful-resources-polymorphic-associations
is there any consensus on this? any comments, suggestions?
thanks,
_c
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
2008 Oct 06
0
Mistaking with polymorphic associations?!
Hello,
I''m trying to solve a problem without success. Look at:
I have 3 models (Recipe, Comments and User)
an Recipe has many Comments
an User has many Comments
an User has many Recipes
I tried to implement this using polymorphic associations with the Comment
model. But the expected behavior needs to be: When a new comment is created
i need to refer it in Recipe and Comments. To
2008 Apr 23
2
Bug in eager loading and polymorphic associations?
Hi friends, i''m usgin the edge version because i need eager loading on
polymorphic associations support, but i see this:
Message.find(:first, :include => :owner) #This generate this query:
SQL (0.000072) SET SQL_AUTO_IS_NULL=0
Message Load (0.000389) SELECT * FROM `messages`
User Load (0.001070) SELECT * FROM `users` WHERE (users.id IN
(1,2))
And this Message.find(:first,
2006 Mar 23
5
Polymorphic associations
I have just updated rails and added polymorphic associations but they
are not working properly. I''m following the recipe 17 of "Rails Recipes"
and I''m getting an "Unknown key(s): as" error. These associations work
properly on the console. The problem occurs when I''m listing the
items... perhaps the problem is pagination. Is this a bug or what
2006 Jul 10
2
Polymorphic associations in reverse?
My app has an association that''s got me scratching my head.
I have Users, and Images. A User has many Images. (Yes, another
picture sharing app, but it''s for a small niche, and it doesn''t end
in -r!)
I would like to express a "Favorite" relationship between both Users
to Users, and Users to Images. This seems like the opposite of the
standard