similar to: has_one :through with :source. How to alias association?

Displaying 20 results from an estimated 1300 matches similar to: "has_one :through with :source. How to alias association?"

2007 Sep 18
2
Making attachment_fu polymorphic
I am working on a small model mixin called attachment_kung to make attachment_fu polymorphic, so you no longer need a different table and Model class for every associated attachment (Productimage, Ad_doc, etc). All you really need is one model and table to handel all your attachments - in some cases, anyway. I have the code working, but have run into one small hitch that I can''t seem to
2007 Oct 09
5
Backticks wrapping SQL values in polymorphic associations...
Hopefully the subject line didn''t scare you. That said... I have a simple polymorphic relationship (is that possible?): class Part has_many :attachments, :as => :attachable end class Attachment belongs_to :attachable, :polymorphic => true end Calling Part.find(:first).attachments yields this SQL error: ActiveRecord::StatementInvalid: Mysql::Error: Unknown column
2006 Apr 22
9
one to many question
1. A category has parent categories. 2. A product is in many categories and a category has many products. 3. Products and category both have images in the same image table. ie. a product and / or category could have multiple images.<=== my question is related to this So among other things I presume I have to do the following: class Category < ActiveRecord:Base #...
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 Feb 15
2
Polymorphic joins work one way, but not the other
I''ve been using polymorphic joins from edge rails based on about 5 lines of advice Rick Olson gave me over IRC. There''s some sparse documentation popping up but it seems to cover a somewhat different case. Anyway - I pretty much got it to work - save for one detail. Here''s what I have: class Event < ActiveRecord::Base belongs_to :attachable, :polymorphic =>
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, -
2008 Sep 23
2
Contional
Hi All, I'm having trouble selecting rows to delete, that i can't seem to overcome. Below is some sample data, i am trying to dedup the data based on each user, and simultaneously the timestamp (at the side i have highlighted expected row to be removed) I've looked at the lag function but can't seem to make it work? My logic ran along the lines of an ifelse statement and then
2007 Dec 20
3
ActiveRecords Eager Loading
Hi, I am doing an eager loading in ruby on rails using below statement ------------------------ Article.find(:all, :include => [:asset, :vote], :conditions=>"assets.parent_id is null", :order=>"stat_final_ranking desc", :limit=>20) --------------------------------------- the above statement resulted in this expensive query.
2008 Oct 29
5
Polymorphic Associations with inheritance
I have two models, Article and Post, that has many Comments. However, both Article and Post are inherited from a BaseContent class like so: class Article < BaseContent has_many :comments, :as => :commentable end class Post < BaseContent has_many :comments, :as => :commentable end and here''s my Comment model: class Comment < ActiveRecord::Base belongs_to
2009 Apr 12
0
rails 2.3 nested forms with has_many through checkboxes
I was wondering if anyone knew of a way to combine the new nested forms in rails 2.3 with a has_many through relationship via checkboxes. Basically I have a page model, a page_category model and a category_items join table. Pages have many page categories through category items. The category_items table is polymorphic so i can use it for other models who need categories (maybe this is
2011 Oct 26
6
Add an index to a form
Hello, I''m having some trouble with forms, my app allows to enter data by using a multi-step form that has 7 steps. There are 3 steps that may let the user to add 1 form, for example there''s a step called "children" and that children has the following fields: * name * age * gender but one father may have more than 1 child and I''m adding another form with
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
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 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
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
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
2010 Mar 29
0
Polymorphic association and has_one retrieval issues
class Address < ActiveRecord::Base belongs_to :addressable, :polymorphic => true end class Client < ActiveRecord::Base has_one :address, :as => :addressable end Now I''am able to create a correct entry in the db for address with addressable_id = 1#client_id addreassable_type = ''Client'' but when I retrieve client = Client.find(1) --> return client
2010 May 05
0
Auto_complete with has_one association
Hi, Have an issue with the rails auto complete, it works fine but I don''t know how to find the id element search in the textfield. Here is what I''ve done: <%= text_field_with_auto_complete :user, :ville_name, { :size => 15 }, { :url => formatted_villes_path(:js), :method => :get, :param_name => ''search'' } %> Model: class User <