Displaying 20 results from an estimated 20000 matches similar to: "Associations and << only setting foreign key not instance"
2006 Jul 31
2
Updating a belongs_to foreign key leaves the old association object available
Perhaps this is intentional, but it seems unlikely:
class Person < ActiveRecord::Base
belongs_to :school
end
p = Person.find(:first)
p.school # nil
p.school_id = School.find_by_name(''High School'').id
p.school.name # High School
p.school_id = School.find_by_name(''Primary School'').id
p.school.name # High School <= Shouldn''t this be Primary
2008 May 07
1
Assigning to the foreign key on a belongs_to association
I''ve encountered what seems like an odd omission in the behaviour of
belongs_to associations: if you assign to the foreign key attribute,
it doesn''t update the associated object (or mark a previously loaded
one as stale) until you explicitly save or reload it.
Let''s say we have a Company model, which belongs_to :city :
>> torchbox =
2006 Aug 09
0
association dows not grt foreign key
I have a 1 to 1 relationship using a similar example as below
(has_one, belongs_to)
but when I do the save, the foreign key of the child object is not set
to the id of the parent object in the relation ship
any ideas?
cheers
dion
---------------------------------
class Person < ActiveRecord::Base
has_one :address
validates_presence_of :email
---------------------------------
end
2006 Aug 09
0
Re: association does not get foreign key
On 8/10/06, Dion Hewson <dionhewson@gmail.com> wrote:
>
> I have a 1 to 1 relationship using a similar example as below (has_one, belongs_to)
>
> but when I do the save, the foreign key of the child object is not set to the id of the parent object in the relation ship
>
>
> any ideas?
>
> cheers
>
> dion
>
> ---------------------------------
>
>
2010 Jan 04
2
[LLVMdev] Tail Call Optimisation
I'm investigating "improving" the TCO facilities in LLVM to provide for "hard" tail calls. Specifically, this would involve extending the existing implementation to discard the stack frame for the caller before executing the callee. I would then like to extend this further by performing hard tail calls on _all_ returning calls that no longer require the stack frame.
A
2006 May 17
2
Association data clobbering (foreign keys too?)
Can someone please confirm or correct the following statements?
If I have the following tables
create table as (id int, [...], b_id int);
create table bs (id int, [...], a_id int);
create table as_bs (a_id int, b_id int);
and the associations woould be defined like this
class A << ...
habtm :bs
belongs_to :b
end
so my Model A has a habtm collection of Bs *plus* a direct
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 Apr 26
6
get foreign key table data
Hi
I?m trying to bring across all related data.
My table clients has a foreign key field that stores the id of an
organization
How can I grab the details of the organization to use in the clients
show.rhtml file?
Thanks
Scott
--
Posted via http://www.ruby-forum.com/.
2006 Jul 10
10
has_many :through and foreign key parameters
I just took my HABTM and turned it into a :through since my join table
has another "non-joiny" attribute.
I went from this:
has_many_and_belongs_to :jobs, :join_table => ''tablename'',
:foreign_key => ''x'',
:association_foreign_key => ''y''
to this:
has_many :jobs, :through =>
2013 Feb 06
0
inverse_of breaks for unsaved child associations during save of parent
I''m willing to write a patch for this issue:
https://github.com/rails/rails/issues/8893
But want to confirm that the new behavior makes sense before I make the
effort.
Essentially if you have an unsaved parent and child, and the parent''s
association to the child has an inverse_of declared on it. When the parent
gets saved, it updates the foreign key on the child, and this
2005 Aug 04
1
Pagination and :include (eager associations)
I have tried to use eager association with pagination, but
the :include option is not supported:
Here''s the one-line pagination call without :include
@link_pages, @links = paginate :link, :per_page => 10, :order_by
=> sort_clause
and here the work around, using the "classic" method
# @link_pages = Paginator.new self, Link.count, 10,
2006 May 23
0
foreign key problem - ''key not found'' error
Hello,
I have the following structure:
model foo
has_many :bars:,
:dependent => true
end
model bar
belongs_to :foo
end
-----------------
I''m doing the following to insert the Foo record and it''s dependent Bar
record:
f = Foo.create(...)
This successfully creates and stores f away in the table.
Now,
b = Bar.new(params[...])
f.bars << b
2005 Dec 16
4
Validation with Aggregation
ActiveRecord supports composed_of for value objects which is
fantastic but one thing that it doesn''t seem to support (or at least
I am unable to find any documentation for) validation of the value
objects.
For example, given the following:
class Message < ActiveRecord::Base
composed_of :sender, :class_name => ''EmailAddress''
composed_of :recipient,
2006 Mar 01
2
Validating that a foreign key is present and ok
How do I validate that a model object''s attribute is a valid foreign
key? The problem is, I can''t check if the attribute is a valid foreign
key if the attribute doesn''t even exist.
For example, every employee must be in a department. In the following
code, if an employee''s department_id is not present then
Department.find_by_id(department_id) might cause
2007 Aug 30
1
belongs_to with foreign keys that reference non primary key columns
Hello,
I have a situation where the foreign key into a table doesn''t
correspond to that table''s primary key:
my_table
-------------
id (pk)
name
...
other_table
--------------
id (pk)
my_table_name (fk references my_table(name))
...
I want to be able to say something like:
class OtherTable < ActiveRecord::Base
belongs_to :my_table, :foreign_key => { :my_table_name
2006 Jun 21
1
Migration with foreign key won''t work
Hi all
I use the plugin which supports foreign keys with migrations:
http://wiki.rubyonrails.org/rails/pages/Foreign+Key+Schema+Dumper+Plugin/versions/12
I have created the following migration file:
class AddArtistsTable < ActiveRecord::Migration
def self.up
create_table :artists, :force => true do |t|
t.column :name, :string, :limit => 100
t.column :artist_type_id,
2006 Feb 03
1
Database Foreign Key - Basic question
Hi all
I''m still waiting on my Agile Rails book to arrive - in the meantime ...
As an exercise I''m making a Help Desk application.
If I have a Problems table with two foreign keys to a People table,
how do I set up my models, problems_controller list method, and then
simply display say my problem submitter person? Here is what I have so
far:
Problems table with columns:
id
2006 Jul 10
3
Can migrations set up foreign key references?
I use Oracle and i really want to use migrations, but there seems to be
no way to setup foreign key constraints. Is this true? If it is then
doesn''t that make migrations useles with Oracle?
Thanks
Chris
--
Posted via http://www.ruby-forum.com/.
2008 Apr 04
1
rails unit testing removes foreign key constraints in test database?
I''ve noticed that when testing is finished that at some point Rails
has removed the foreign key constraints from my test database. Does
anyone know where this foreign key constraint deletion occurs in the
source code. I''d like to turn it off.
Thanks,
Peter
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
2007 Oct 07
2
How specify foreign key column name in model?
In a model declaration I can specify the name of the primary key
column with
set_primary_key "CUSTOMER_NUMBER"
How can I set the name of a foreign key column that does not conform
to the RoR naming convention. Does the following work?
set_foreign_key "CUSTOMER_NUMBER"
If not, how can I specify the name of the foreign key column? Thanks.