similar to: Polymorphic association and has_one retrieval issues

Displaying 20 results from an estimated 5000 matches similar to: "Polymorphic association and has_one retrieval issues"

2007 Aug 03
0
acts_as_paranoid and Association Extensions (has_one troubles)
Hi... Isn''t there a proper way or hack/workaround for the following? * For the example with unfortunate disabilities.. look below,,, Usage of has_* (associationmethods) do {def with_deleted AccociatedModel#with_scope} {Paranoid''s#find_with_deleted}... The has_one associations give me a nil object when invoking it with Model.association_OBJECT.with_deleted. Has_many does like
2006 Jul 30
3
ActiveRecord - Multiple Address for a single record
I''m trying to figure out the Rails way to model the following problem: I have 2 tables. One (let''s call it location) contains a single address. The other (let''s call it company) contains 3 address. I''m trying to figure out the best way to model this. I''ve created an address table, a set up the model as follows: class Address <
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
2007 Apr 21
0
has_many / has_one polymorphic with conditions
I''m looking for a way to make this work (I think the code is more explanatory at this point): ## THIS WORKS has_many :images, :as => :imageable, :dependent => :destroy, :order => ''position ASC'' # @product.images => # ## THIS DOESNT has_one :featured_image, :as => :imageable, :conditions => "position = 1" # @product.featured_image =>
2010 Oct 07
1
Question on polymorphic association
I have 3 models . Doctor, Patient and User with following associations class Doctor < ActiveRecord::Base has_many :patients, :dependent => :destroy has_one :user, :as => :userable accepts_nested_attributes_for :user end class Patient < ActiveRecord::Base belongs_to :doctor has_one :user, :as => :userable accepts_nested_attributes_for :user end class User <
2006 May 05
2
Dumb polymorphic association question
Hi, Why is it that polymorphic associations only work with the :has_many and :belongs_to relationships? Why can''t it be a :has_one? Matt
2007 Oct 18
4
Polymorphic Association?
Hi there- I''m a newbie to this board, RoR, and web development in general. So please forgive me if this is in the wrong place or if the solution is really simple... I''m trying to conceptualize the relationships between a series of models for a page creation function. What I''d like is to have a Content Page which consists of a series of Content Blocks. The Content
2008 Sep 29
1
has_one :through with :source. How to alias association?
Hi to everyone, I have the following models: class Attachment < ActiveRecord::Base has_attachment :content_type => [:image, ''application/pdf''], :max_size => 3.megabytes, :path_prefix => ''../private/attachments'', :storage => :file_system, :processor => :rmagick,
2011 Sep 04
1
polymorphic association
Hello, I have a scenario where I want to save a author image and book image to assets table... I am using a polymorphic association. And author_name is inside the books table. now when I save the image the imageable_type says "Book" for both. And off-course it''s a correct behavior, but I am just trying to figure out is there any way where I can save author image and
2006 Apr 04
1
What is the best way to handle this? It''s not a good use of the new Polymorphic-Association thingy is it?
Just getting back into Rails, so apologies. Just a bit of advice please. I''m trying to rewrite the change control app that I wrote originally in VB/Oracle. It''s used heavily by our project and customer and seems a good project to rewrite in rails, if not for this customer then perhaps for another. Anyway, I have decided to go with MySQL this time and have the following
2006 May 09
7
polymorphic relation question
I am trying to get polymorphic relations to work for my app. What I am trying to do is explained by this picture http://iroll.org/code/ I can''t figure out the code for in the controller to create a new phone_number and assign it to a person. I have tried everything I can think of. A) do my models look correct? B) what would the commands look like in the console or a controller action
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 Mar 24
7
Polymorphic associations?
I''ve read the stuff about polymorphic associations here: http://wiki.rubyonrails.org/rails/pages/UnderstandingPolymorphicAssociations But I''m not sure what exactly they are and what their advantage is. Are they the same as HABTM, but they''re "two-way"? Joe -- Posted via http://www.ruby-forum.com/.
2008 Feb 19
0
Issue with Observers and has_one association...
Hey Guys, I''m getting a peculiar bug working with Observers and has_one associations. When a has_one association is invoked by an Observer it always returns null. I looked in the development.log file and the SQL for the has_one association isn''t even being executed. On the other hand, when I replace the has_one association with just a hand crafted method, it does get called
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 May 16
1
saving a has_one association question
Hiall, Say I have class User has_one :community end class Community belongs_to :user end Will the following work and both save user and community if validation doesn''t fail? user = params[:user] user.community = params[:community] user.save Or do I have to do something like the following user = params[:user] if user.save user.community = params[:community] end to be on the
2006 Mar 23
0
optional has_one association
Hi! I have a has_one association which is used for extending an entity, like: class User < ActiveRecord::Base has_one :user_ex #name, email end class UserEx < ... #country, city, street... end The UserEx entity is optional (there are users without extended info). My problem is: if u is a User object which has no user_ex extension, activerecord always tries to fetch the UserEx
2008 Apr 21
0
Lost Polymorphic Associations in development environment causes delegate :blah, :to => to fail
Hi All I have been struggling with this issue for a long time now. And before I began to describe the problem its important to know that this problem happens only in Development environment. I am using Rails 2.0.2, here are my associations class User has_many :comments has_one :profile, :as => :profileable delegate :email, :to => :profile end First call to comment.user.email works
2014 Apr 19
0
How to has_one/belongs_to association only return the objects unassociated in combobox?
I have two models (Car and Driver) and a combobox to select which driver belongs to which car. I want the combobox just show the objects that have not yet been associated. # vehicle belongs_to: driver # driver has_one: vehicle # simple_form # vehicle/_form.html.haml = f.association: driver, label_method: :name, value_method: :id How to ensure validation before saving, to avoid problems of
2007 Mar 01
0
association extensions - has_one
Hi, I''m struggling with something that must be very common pattern, and want to do it the correct rails/ruby way but am a bit dense ! I have users - an admin user, registered users and a guest user (using ModelSecurity) For many of linked associations I want the admin to be able to list or edit all instances, the registered user only their own one and guest none at all. So somehow I