similar to: Why does belongs_to handle "conflicts" this way?

Displaying 20 results from an estimated 1100 matches similar to: "Why does belongs_to handle "conflicts" this way?"

2006 Nov 09
2
redefining the method belongs_to in ActiveRecord::Base
Hi. I''ve tried to redefine the method belongs_to in ActiveRecord::Base, so every time a model is defined as belonging to :attachment, it should have some additional methods. I tried to do an alias of belongs_to, but this was not successful. The error message in Webrick was > Booting WEBrick... ./script/../config/../lib/ActiveRecordExtensions.rb:67: undefined method
2006 Oct 13
3
Validation errors in has_one/belongs_to relationships.
I have two objects, QuoteInput and Insured. QuoteInput has one Insured and Insured belongs to QuoteInput. I don''t understand what I''m seeing. I assign an Insured to a QuoteInput. The Insured object has invalid data. I call save! on the quote input. QuoteInput has no validations. I expect two things to happen - 1) an exception should be thrown, indicating that there was a
2006 Apr 12
0
Sorting with SQL for has_one, belongs_to relationship
I''ve been using this sort helper to have sortable tables. http://wiki.rubyonrails.com/rails/pages/Sort+Helper I''ve encountered a situation where I need to sort a column that is not part of a table, but it''s related table. For example, say I have db tables called foos and bars. Foos have fields called name and title. And bars have fields called note and foo_id. Foos
2006 Jun 03
1
Can I tell if the associated record is new in a belongs_to save?
In a belongs_to association, is there a way to tell if the associated object was newly created? Hopefully this will explain my question: A Firm class declares has_many<http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000530>:clients and a client class declares
2006 Mar 13
1
adding custom cache field
Hello, I needed to add custom cache field for one of my application. I thought I will share the code showing how to do this. This code below creates and maintain a custom cache field, for keeping track of totals. Say, you have accounts, and for each account there are transactions (either deposit/withdrawal), and one will like to keep track of the total balance for an account. So, let there be a
2006 Aug 16
0
acts_as_paranoid and alias_method_chain
when i require acts_as_paranoid I''m getting: undefined method `alias_method_chain'' for #<Class:ActiveRecord::Base> (NoMethodError) It happens in acts_as_paranoid''s init.rb. here''s the whole file. the alias_method_chain is near the bottom. please advise. class << ActiveRecord::Base def belongs_to_with_deleted(association_id, options = {})
2007 Jan 28
0
problems with acts_as_paranoid (noticed while using acts_as_versioned)
hello, I''m using the trunk versions of both plugins. I''m running into this error when I run a migration to try and create the versioned table for the model ''Note'' stack level too deep /Users/Adam/dev/sweetspot/app/trunk/config/../vendor/plugins/ acts_as_paranoid/init.rb:5:in `belongs_to_without_deleted''
2006 Oct 31
4
Auto-increment lost during migration.
Hi. I get some strange results when using rename_column on a primary key in a migration. It seems like the migration script removes the auto-increment property if you rename a column. This is a minimal example. create_table :foo, :primary_key => :foo_id do |t| t.column "name", :string end # renaming the primary key makes auto-increment disappear. rename_column
2006 Apr 28
1
object passing for distributed model
I''m still fairly novice when it comes to rails so i was hoping someone here could shed some light on the correct way to do things. I have a central object that has :has_many relationships with 5 other objects. So i have one table, foo, and 5 other tables have foo_id to associate each row with a foo object. Now, i have a page that renders all the "foo" associations. I chose
2006 Jan 03
4
Set the foreign key constraint column name?
I am applying Rails to an existing schema and not sure how much the existing developers will let me go in and rename things. So I need to discover the limits of what I can change with Rails. I''ve found set_table_name and set_primary_key, which have been very useful. If I have a "foo has_one :bar" relationship, but then in the bar table my column is named "fooid"
2006 May 31
7
How do you create a controller & view to create a list of objects?
I''m trying to figure out how to design a view and controller to work with a simple collection. I have a Foo that has many Bars, so here''s what I did: $ ruby script/generate model Foo $ ruby script/generate model Bar (Uncomment t.column, :name: :string in foo and bar migrations) (Edit Foo.rb and Bar.rb, add has_many :bars to Foo, belongs_to :foo to Bar) $ rake db:migrate $ ruby
2008 May 16
0
Problem with :action => 'destroy' in url_for
url_for( :controller => ''foo'', :action => ''destroy'', :id => 1 ) => ''/ foo/1'' url_for( :controller => ''foo'', :action => ''destroy_x'', :id => 1 ) => ''/ foo/destroy_x/1 url_for( :controller => ''foo'', :action => ''destroy'', :foo_id => 1 )
2007 Oct 22
1
self-referential habtm: why are my keys null?
I''m trying to set up a directional self-referential HABTM to represent an arbitrary semi-hierarchical structure; it works for any data prepopulated into the db, but when I try to create a new relationship, I just get NULLs in both key columns (or 0''s if I turn on the no-null constraint). Here are the migrations: class CreateNodes < ActiveRecord::Migration def self.up
2006 Jan 23
5
validates_uniqueness_of :username, :if => !self.new_record?
Hi all I want users to register on my page. To register, they only have to deliver an email and a password. Then a link with an activation token will be sent to them, and after clicking the link the user sees a page where he should fill in further details, means: a username. My model looks like this: class Member < ActiveRecord::Base validates_presence_of :username, :if =>
2005 Apr 27
4
has_many syntax
Hi all, I have the following inside of an AR class definition: relationships=ActiveRecord::Base.connection.select_all(my_relationships_sql) relationships.each do |relationship| has_many RelatedItems, :class_name => relationship[''RelatedClass''], :foreign_key => relationship[''ForeignKey''] end This kind of works, but how can I assign the name of the
2006 Mar 19
2
Multiple polymorphic belongs_to declarations
I have the following models: class Card < ActiveRecord::Base belongs_to :deck belongs_to :front, :polymorphic => true belongs_to :back, :polymorphic => true end class TextContent < ActiveRecord::Base has_one :card, :as => :front has_one :card, :as => :back end The conflicting has_one declarations don''t work. What I need is
2009 Aug 23
0
Best way of moving some jQuery from a view helper
I have a helper that uses some jQuery code that I would like to move out of the helper method. I am trying to move it to application.js but it will probably end up in a different file. I have two reasons for wanting to do this. 1) I want to keep all my jQuery code seperate to my HTML code 2) I want to change the append to an appendTo so I can add a highlight effect, appendTo which is proving
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
2011 Jun 15
1
.new_record? and :_destroy
Rails version 2.3.8 I have a ticket model that has many comments the comments have an attribute called "admin" -- is this a comment added by an administrator the ticket has an attribute called "admin_email_address" I want to validate when saving the ticket and say "if I have a new admin comment, make sure I have an admin_email_address" In my ticket model, the
2005 Dec 22
0
Errors object missing when saving AR in Web Services method
Hello, I''m not able to get Errors object when saving some Model instance in ActionWebService::Base subclass. I want to create API method that will return ID of the object when saved successfully. When validation fails and the object is not saved I''d like the method to return ID, as well as the array of ValidationError custom struct. But I cannot fill in this because unsaved