Displaying 20 results from an estimated 30000 matches similar to: "has_and_belongs_to_many polymorphic question"
2012 Sep 08
3
Polymorphic has_and_belongs_to_many association
Hi,
I''m currently having the situation where I have to implement a polymorphic
has_and_belongs_to_many by introducing an in between model that handles all
the "has_many :as" and "belongs_to :polymorphic" association
implementations... and is not doing anything else. Thing I don''t like it
here is, I am unnecessarily loading AR instances only to execute SQL
2006 Nov 22
1
Polymorphic Data Modelling Question
Hello,
I am not sure of the best way to model this situation in Rails and
would appreciate some guidance.
An order can hold multiple line items. Each line item is for a
certain number of any given product. There are four products, each
in a different table because they have completely different
attributes. So I have:
Order
- has many LineItems
LineItem
- belongs to an Order
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 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
2009 Oct 05
0
ActiveRecord Polymorphic Inheritance
I am using RoR ActiveRecord polymorphic inheritance and was wondering
if it''s possible to access the base class'' association methods in the
invocation of either to_xml or to_json without having to depict the
base class data in the serialized string. Here are my classes:
# base class
class Asset < ActiveRecord::Base
belongs_to :resource, :polymorphic => true
2005 May 23
1
has_and_belongs_to_many dual insert error ?
Hi !
(See references at the end)
I have a slight problem. Whenever I save one of my domain models, which
contains an has_and_belongs_to_many relationship with another one, the
relationships are doubled.
My domain is a series of pictures, where each picture can be tagged with
one or more words. So, a picture of my dog could be tagged "Jordy, Dog,
Dog 2005", for example.
In my
2006 May 11
1
ActiveRecord collection_select and has_and_belongs_to_many
Hello everyone, first post to the list and a relative newbie to Rails
development. Done quite a bit of JSP, PHP, HTML, XML etc and thought I would
kick the tires on Rails to see if it can speed up development for internal
applications. Anyway, I am running into a problem that is just driving me
crazy and everything I read on the net doesn''t seem to help. I was hoping
someone here might
2008 May 13
0
Polymorphic naming difficulties
Hi all. I''m having a problem naming a polymorphic relationship. Here''s
my thinking...
First, an analogy. You''re walking through the mall. Through a window you
see a game you''re interested. I''m attempting to model the relationship
between your interest and the game you''re interested in.
I have an InterestList. It''s job is to maintain
2005 Mar 01
0
has_and_belongs_to_many problem
I''m having a problem with a has_and_belongs_to_many (habtm)
association between two models with extra attributes. I''m writing a
comic book database, and each issue has many creators on it. Thing
is, some creators perform multiple duties. They may write one issue,
draw another, etc.
However, if I add a creator twice to an issue and try to delete it, it
removes both creators:
2007 Jan 19
0
Do transactions fail with polymorphic has_one relationships?
I have an AR::Base descendant with a complex object graph beneath it,
like so:
ArtisanQuoteInput has_one QuoteInput and then QuoteInput has several
objects attached to it. Note that the relationship between
ArtisanQuoteInput and QuoteInput is polymorphic, so the relationship in
A is written
has_one :quote_input, :as => :program_quote_input
If @artisan_quote_input is an instance of
2006 Sep 22
2
possible to create polymorphic relationship with STI models?
I would like to associate a ‘product’ model with 3 models inherited from
‘image’: part, action and accessory.
I have it working with Has_many :through relating products to images
through attachments, I then have to determine the ‘type’ of the STI
extension. This means i have to go product.images. While this is ok, i
can see it getting tricky when i want to go products.images <<
2006 May 08
2
Queries with has_and_belongs_to_many relationship
I was able to create a has_and_belongs_to_many relationship for my app,
but now I''m not too sure how to write queries for it.
Basically, I have a table ''courses'' that has_and_belongs_to_many
''categories'' and vice versa
So I''m trying to figure out how I would find only the courses that
belong to a category that I specify.
Let''s
2006 Feb 26
3
Representing relationships between model objects
I''m a little stumped on how to approach the subject of representing
relationships between a single model object.
Basically, I want a User to be able to mark others as Friends,
Contacts, etc. The caveat is that User A can mark User B as a Friend
but that doesn''t mean User A is marked as a friend by User B. It can
either be a one-way relationship or two-way relationship.
Right
2005 Oct 05
0
has_and_belongs_to_many on legacy DB
I am working with mapping ActiveRecord onto a legacy database. All is going
well (using set_table_name, set_primary_key, etc), but I can''t get my
many<=>many relationships to work.
My contrived example of the situation:
Student has_and_belongs_to_many Teachers. This is mapped via table
student2teacher where the foreign keys are studentId and teacherId. The
primary key in Student
2006 Mar 30
0
Polymorphic compatible with HABTM?
Can you use polymorphic with a habtm relationship?
If so I would assume the join table would contain both the
foreign key and the type for both sides of the table. The
API documentation is unclear, although it may be out of date.
I would prefer not to. I am trying to model a Person, who
may be associated with many different models. A person
may also be a member of one or more Teams, each of
2006 Nov 09
2
help with join tables and has_and_belongs_to_many
Hi,
I have a user model and a privilege model. They have the
has_and_belongs_to_many relationship. Here are the model defs:
class User < ActiveRecord::Base
belongs_to :status
has_and_belongs_to_many :privileges
end
class Privilege < ActiveRecord::Base
has_and_belongs_to_many :users
end
Now I have a migration script to create the join table and populate a
few users with some
2011 Oct 11
5
Polymorphic association with Active Admin
I have a belongs_to polymorphic association and I don''t know how to
create and edit my models of that relationship with active admin.
If anyone can help me, please do.
Thank you,
Rodrigo
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to
2006 Mar 08
0
combining STI + polymorphism + rich self HABTM : how to ?
Hi all,
I need to model simple typed polymorphic relations:
''John'' [''works_for''] ''Bill''
''John'' [''speaks_for''] ''Microsoft''
''Microsoft'' [''hold_shares_of''] ''Apple''
I''m having a hard time combining :
- S.T.I.
2006 Jul 17
1
Updating multiple children from one page
Hello,
I have a model called invoice and one called lineitem. An invoice
has_many lineitems, and an lineitem belongs to an invoice. I have a
model method that calculates the price of a lineitem, and one that
calculates all lineitems in an invoice. I want to have an edit page
that lists all the invoices lineitems and their calculated prices, with
a text field for a person to change the
2011 Jan 11
0
[PATCH] Polymorphic belongs_to association with :conditions issues
Hey all,
Could use a few eyes on a couple of very simple patches at https://rails.lighthouseapp.com/projects/8994/tickets/6262 if any has some time.
The issue (from the ticket description):
If you define a polymorphic belongs_to association and it has conditions on it, those conditions cause a NameError when you try to access the target object, of the style saying "hey, there''s no