similar to: Optimise this association?

Displaying 20 results from an estimated 11000 matches similar to: "Optimise this association?"

2006 Apr 24
2
Checkboxes - Saving a Checked record to another table
I am displaying a bunch of records from a table called "assets". Next to each record i have a checkbox. When this box is checked i want to be able to save the id of the record into another table called "flagged_assets". All I need is the ID, nothing else. Im struggling with the logic to save to another table. I know how to do it if the asset_id is already in the
2008 Mar 13
3
Refreshing a page gives a "stack level too deep" error.
I''m converting our app into restful rails. A couple of my classes (Resource and Asset) have a has_many relationship with each other - here''s the routes: map.resources :assets, :has_many=>[:resources] map.resources :resources, :has_many=>[:assets] I''m getting something weird in my view pages. When i go to /resources/4/assets it works. I go to the page
2007 Jun 26
4
Can I stub a method on a belongs_to association:
describe Asset, " when destroyed" do fixtures :assets, :videos, :sites, :publish_settings before(:each) do @asset = assets(:test_asset) @mock_hook = mock("hook") @asset.video.stub!(:hook).and_return @mock_hook # error occurs here end it "should call the delete hook" do @mock_hook.should_receive(:update).with("test_video",
2011 Jun 04
0
Rails 3.1 : Complex database query with Arel 2
Hi, I''ve search for documentations on queries with Arel 2 but there is pretty nothing and all I''ve found is for Arel 1 so I''ve run into NoMethodError: undefined method `[]'' for #<Arel::SelectManager:0x00000003f1b820> errors with join syntax. My query is barely simple but involve nesting queries. I have 4 tables. Assets, Deposits, Orders and OrderLines
2010 Apr 05
0
Risk Assessment Application
I am going to be developing a Risk Assessment system for a secure environment whose database will double as an asset management system. Or at least the Risk Assessment stuff will be an outcropping of the asset management system. Has anyone had any experience with this or a similar project? This is my first attempt at a Rails project after spending a few weeks reading books and getting a general
2009 Nov 12
0
Problem with has_many :through, :uniq => true with polymorph
Didn''t have quite enough space to describe it there...basically i''m having a problem with the :uniq option in my tags. I''m using acts_as_taggable_on_steroid which adds these associations to my Resource class: Resource has_many :taggings, :as => :taggable, :dependent => :destroy, :include => :tag has_many :tags, :through => :taggings, :uniq => true
2007 Nov 08
0
Dynamic relation with eager loading
A model has 2 columns in its table asset_type_id asset_id the asset_type_id links directly to the table asset_types via a belongs_to asset_types contains a single column ''name'' method_missing in the model says when you call a method matching /^asset.*/ call the corresponding method substituting ''asset'' for the contents of asset_type.name (ie. the name in
2007 Aug 30
3
has/belongs to many sql error
I have a model Asset which has_and_belongs_to_many :tags. Tag has only one field, name. There is a table assets_tags which only has an asset_id and a tag_id. I can add a tag to one asset. If I try to add the same tag to another asset though (asset.tags << tag) I get this error: Mysql::Error: #23000Duplicate entry ''4'' for key 1: INSERT INTO assets_tags (`tag_id`, `id`,
2008 Jun 09
0
association build changed under rails 2.1?
class Post < ActiveRecord::Base has_many :assets end This used to work fine self.assets.build(attrs) but under 2.1 it works sometimes and not others. Don''t know if that is because Asset uses attachment_fu (which I''ve updated to latest) But this is okay under 2.1 self.assets << Asset.new(attrs) I''m probably doing something wrong. Which way is, well,
2005 Dec 20
0
validates_uniqueness_of on has_and_belongs_to_many
I am trying to create a model that allows only unique assets to be added to a category. However, they could be added again to a different category. Finally, an asset can be shared across many categories. So my question is how do you check the uniqueness across a join table? This does not compile.... has_and_belongs_to_many :categories, :foreign_key => ''asset_id''
2007 Sep 06
4
HABTM association with own class?
If I have a class, Asset, which has and belongs to many associated Asset objects, how do I do this? has_and_belongs_to_many :associated_assets, :class => "Asset", :foreign_key => ?????, :association_foreign_key => ????? Right now, my table has a :first_asset_id and a :second_asset_id, but I don''t see how the objects themselves are supposed to distinguish one from the
2011 Aug 22
0
Paperclip nested resources problem
My models: class Country < ActiveRecord::Base has_many :regions has_many :assets, :dependent => :destroy accepts_nested_attributes_for :assets end class Region < ActiveRecord::Base belongs_to :country has_many :appartments has_many :assets, :dependent => :destroy accepts_nested_attributes_for :assets end class Asset < ActiveRecord::Base belongs_to :region
2007 May 28
2
Rails, respond_to? over anonymous module (extend has_many).
Hello List, I''m trying to generate examples for some list-helpers I have coded which use in my projects. Basically, the Playlist class uses one anonymous module in has_many that acts as helper between acts_as_list and my desired API: class Playlist < ActiveRecord::Base # associations go here has_many :playlist_items, :order => :position, :dependent => :destroy has_many
2009 Oct 27
5
Unwanted call to validates_associated
In my schema, a question has_many :answers. When the validations are run on a question, and one of the answers is not valid, then i get "Answers is not valid" coming out of errors.full_messages. I don''t want this, i''m already testing the validity of the answers and this is an ugly and uninformative error message. It looks like it''s the message i would get
2006 May 05
0
Missing documentation for find_in_collection? Trying to drill down in a 4 level has_many association fails
I''ve been reading up in ActiveRecord::Associations and playing around with my app via the console and found some interesting methods via the code completion of IRB, but I have no idea how to use them and can only find one hint in the API http://api.rubyonrails.com/classes/ActiveRecord/Associations/ ClassMethods.html It mentions here in the has many associations that if you use the
2010 Feb 17
1
Paperclip and viewing images
I have two objects Task and Asset and I want to view image in show task. Here is my to models Task.rb has_many Assets :as => :attachable And Asset.rb has_attached_file :photo, :styles => { :large => "371*251>", :small => "72*72>"}, :url => "/assets/:id/", :path =>
2006 Aug 06
1
Sorting through relationships
Hi, I''m having a rather annoying problem which can only be explained with an example, so here we go. I have a Person class which has_many :assets. An Asset has_one :game. I would like every Person''s asset to be sorted by its game''s title, similar to this: has_many :assets, :order => ''game.title'' That doesn''t seem to work. A
2006 Oct 30
2
It this possible: finder_sql-like behavior for belongs_to?
Guys, I have a need to support as has_many/belongs_to relationship on a legacy(kind of) schema. The reason I say kind of is that the schema does have "id" columns that are used in many associations, but this particular has_many/belongs_to association needs to support different ones. I''ve attached to code at the end of this email. Suffice it to say I need to use the standard
2006 May 04
0
Complement set association to has_many/through?
I have two models, A and B, with a straightforward many-to-many has_many/through association between them. So, in A I have the association processed_bs and in B I have processedby_as. This works fine. Now, I would like to also have an association unprocessed_bs in A, which holds all Bs that _aren''t_ in processed_bs. I can write a method in A that returns all those objects as a list
2010 Jan 25
0
has_many, :finder_sql, setting attributes
Hi all, My question is somewhat complicated, but bear with me. My project has a number of models: User, Program, and Team. Users belong to multiple Programs. Programs have multiple teams, but Teams belong to one program. For each Program a User belongs to, he can belong to multiple Teams. (Think of this in an athletic context where users are athletes, programs are universities). So my