Displaying 11 results from an estimated 11 matches for "primary_key_name".
2008 May 07
1
Assigning to the foreign key on a belongs_to association
...rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1094,6 +1094,13 @@ module ActiveRecord
instance_variable_set(ivar, new_value.nil? ? nil :
association)
end
+ if association_proxy_class == BelongsToAssociation
+ define_method("#{reflection.primary_key_name}=") do |
target_id|
+ instance_variable_set(ivar, nil)
+ self["#{reflection.primary_key_name}"] = target_id
+ end
+ end
+
define_method("set_#{reflection.name}_target") do |
target| return if target.nil? a...
2011 May 11
2
Issue with Arel::SelectManager and insert Method
Hello,
Arel::SelectManager (arel 2.0.9) uses following statement to insert a
new record:
@engine.connection.insert im.to_sql, ''AREL'', primary_key_name,
primary_key_value
But in DatabaseStatements insert ist defined as:
insert(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
Actually, Arel::SelectManager does not use the sequence name. This
leads to issues for instance with
activerecord-jdbc-adapter and Oracle, when you use sequ...
2006 Apr 19
2
Using Reflections to find out ActiveRecord class association
...ent
end
and then I do
Component.reflections[:branches].active_record
I would expect that to be Branch but it is in fact Component.
The inspection of Component.reflections is as below
{:branches=>#<ActiveRecord::Reflection::AssociationReflection:0x37d86d8
@active_record=Component, @primary_key_name="component_id", @options={},
@name=:branches, @macro=:has_many>
How can I get what class the has_many is to?
I am using Rails 1.1/Ruby 1.8.2
Thanks,
Steve Tuckner
--
Posted via http://www.ruby-forum.com/.
2010 Oct 06
2
reflect_on_association method
Hi all, I am having trouble trying to use reflect_on_association
method with given the simplified model:
class Order < ActiveRecord::Base
belongs_to :contractor, :class_name => "BusinessUnit"
end
I expected the reflect_on_association method to return
associated_foreign_key "contractor_id" but it returns
"business_unit_id":
ruby-1.9.2-p0 >
2010 Mar 24
1
How to stub a has_many relationship in Rails 2.3.5
...pears it is expecting some sort of
association object that responds to owner_quoted_id
Like I said, we didn''t have any problems until upgrading from Rails 2.3.4 to
Rails 2.3.5
In case your interested, it is the configure_dependency_for_has_many method
that calls: "#{reflection.primary_key_name} =
\#{record.#{reflection.name}.send(:owner_quoted_id)}"
Any help would be greatly appreciated!
Ben Fyvie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100324/db86f739/attachment-0001.h...
2006 Jun 13
6
Dead horse: validates_associated
Regarding validates_associated...
Let''s say I have:
article belongs_to author
But for whatever reason, I want an article to also be written
anonymously and therefore not require an author. Then I have:
Article:
belongs_to :author
validates_associated :author
But I DON''T have validates_presence_of. What I want to do is validate
that an author is valid --if it is
2008 Sep 25
1
defining polymorphic type condition
...on.options[:as]}_id
= #{@owner.quoted_id} AND " +
"#{@reflection.quoted_table_name}.#{@reflection.options[:as]}_type
= #{@owner.class.quote_value(@owner.class.base_class.name.to_s)}"
else
@finder_sql =
"#{@reflection.quoted_table_name}.#{@reflection.primary_key_name} =
#{@owner.quoted_id}"
end
@finder_sql << " AND (#{conditions})" if conditions
end
This cannot easily be changed. The type condition should be a function
call so we could easily modified. Has anybody thought about this?
--
Posted via http://www.ruby-for...
2006 Apr 25
2
Upgrade 1.0 => 1.1.2 Broke My App (environment.rb ?)
...e old syntax, it may not continue to work in future releases.
For upgrade instructions please see: http://manuals.rubyonrails.com/read/book/19
LineItem Columns (0.361000) SHOW FIELDS FROM line_items
You have a nil object when you didn''t expect it!
The error occured while evaluating nil.primary_key_name
c:/program
files/ruby/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/associations/belon
gs_to_association.rb:52:in `foreign_key_
present''.....
I figured out to run ''rails .'' and then do a full compare, adjusting any differences as
needed. That was easier t...
2007 Oct 21
13
[ANN/RFC] Rathole, a fixtures extension plugin
Like lots of other folks, I''ve been searching for a way to scratch my
fixture itches. Rathole is my extraction of a few techniques we''ve
successfully applied at my day job.
We''ve been using Rathole for a month or so now, but I''d really like
some feedback from a wider audience. Rathole tackles:
* Conflicting PK''s (no more id''s in fixture
2008 Sep 03
5
Eager load associations in Oracle problem with more than 1000 records
I think Rails 2.1 introduced a bug when eager loading of associations
with Oracle. In 2.1 ActiveRecord loads the included table with a big
''IN'' query: ''where association.id in (1, 2, 3, 4...)''. The problem
is that Oracle has a hard limit of 1000 values in an IN clause. I get
this error:
''OCIError: ORA-01795: maximum number of expressions in a list
2006 Jul 27
25
Why are has_one objects resaved when the parent is saved?
If the associated object of a has_one association has been loaded, it
is resaved when the parent is saved. Eg:
class Person < ActiveRecord::Base
has_one :user
end
class User < ActiveRecord::Base
belongs_to :person
end
p = Person.find(:first)
p.save # As expected, nothing happens with the user association
p.user # Loads the associated object
p.save # As well as saving the person, the