Displaying 20 results from an estimated 26 matches for "foo_id".
2006 Jul 16
0
Why does belongs_to handle "conflicts" this way?
...ssion.
>> f = Foo.create
=> #<Foo:0x270ec10 @attributes={"name"=>nil, "id"=>1},
@new_record=false, @errors=#<ActiveRecord::Errors:0x269fd10
@base=#<Foo:0x270ec10 ...>, @errors={}>>
>> b = Bar.new
=> #<Bar:0x26989d4 @attributes={"foo_id"=>nil}, @new_record=true>
>> b.foo_id = 10
=> 10
>> b.foo = f
=> #<Foo:0x270ec10 @attributes={"name"=>nil, "id"=>1},
@new_record=false, @errors=#<ActiveRecord::Errors:0x269fd10
@base=#<Foo:0x270ec10 ...>, @errors={}>>
>>...
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 :foo, :foo_id, :bar_id
Is this a known problem, any beautiful solution available? Maybe use
change_column instead?
Best regards,
Tobias Nurmiranta
--~--~----...
2006 Jan 03
4
Set the foreign key constraint column name?
...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" or some other thing that is not "foo_id", is
there a similar helper command I can use to change it? Everything''s
working swimmingly for me, except when I get to this bit and it errors
out telling me "cannot find bar.foo_id" and I can''t figure out a way to
point to bar.fooid and say "There it is....
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 Jul 04
2
How to make WHERE foo_id IN () query?
Hi,
There are 3 models:
A has_many :Cs
B has_many :Cs
C belongs_to A and B
I got a single object of A and an array of B objects. How can I get
all Cs that have a_id equal to object A.id *and* b_id that belongs to
an object in Bs array?
Regards
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails:
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 to
render each piece in its own component. So on the main page i have a bunch
of render(:component... lines.
Given this, whenever i render a component, i pass it the foo object...
2013 Feb 28
2
Create polymorphic resources
...r do
resources :comments
end
A new comment is posted to /foo/1/comments or /bar/1/comments. When I''m in
the Comments#create action, how am I supposed to create the comment through
either Foo/Bar?
If it is a comment for a Foo resource, I need to do:
@commentable = Foo.find(params[:foo_id])
@commentable.comments.create(....)
But if it''s Bar I need to do:
@commentable = Bar.find(params[:bar_id])
@commentable.comments.create(....)
What I do now is to use this method:
def find_commentable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.cons...
2006 Jul 26
15
Rails without a primary key
I''ve been trying to use Rails on a database where the biggest
datawarehouse-style table doesn''t have a primary key. It really
doesn''t make sense and just adds extra unnecessary space. I do have,
however, a column that I normally use to search on (IP) that returns
many rows. The table also references several other tables through
rails-friendly foreign keys.
Simple AR
2010 Feb 01
3
validating both sides of a has_one relationship breaks pickle/machinist tests
A lot has been posted about validation issues with associations,
however, I don''t see this issue addressed specifically.
ex:
class Foo
has_one :schedule, :dependent => :destroy
validates_presence_of :schedule
class Schedule
belongs_to :foo
validates_presence_of :foo_id
this creates a circular dependency that breaks test frameworks like
pickle and machinist.
At first I was surprised a little that you can contsruct objects with
this constraint
...you can of course with "new" and "save"
...though I it sounds like the destroy will cause a problem...
2006 Jan 08
1
Using many-to-many relations in tests
Hello,
I have some many-to-many relations, I would like to use in my tests. But
I''m not sure what I should put in the fixtures for it?
How do I add those relations in the testing environment?
Greetings,
Gitte Wange
2008 May 16
0
Problem with :action => 'destroy' in url_for
...#39;', :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 ) =>
''/foo/destroy/?foo_id=1''
Anybody knows what happens? No REST routes defined.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this gro...
2006 Jan 21
7
n-way joins
...y (3 or 4 way) joins in Rails (where the join tables
contain extra data as well.)
Let me give you my basic entities:
foos
id - pk
name - unique
bars
id - pk
name - unique
bazs
id - pk
name - unique
frozs
id - pk
name - unique
then i have two separate join tables:
foos_bars_bazs - 3 way join
foo_id\
bar_id > primary key/unique
baz_id/
value
foos_bars_bazs_frozs - 4 way join
froz_id\
foo_id \
bar_id \ primary key/unique
baz_id /
value
Now, my use cases for access are:
1. Given a foo, find all { bar, baz, value } associated with it (i''d
really like to get back bars and bazs,...
2005 Aug 08
7
Problems with ./scripts/generate scaffold
Hi all,
I''m new to rails after having used perl for most of these things, and am
trying to get my head around the generate script for a project playing
around
with.
If I do:
./scripts/generate controller Device
I get app/controllers/device_controller.rb
where I can then add:
scaffold :device
However, if I want to actually generate the scaffolding so I can make
some changes:
2006 Mar 02
6
Question about $F()
Hi Guys,
Maybe this is a stupid question, but I am confused at the moment.
The $F() function is a handy shortcut to get the value of the an input field.
So, doing something like $F(''name'') is equivalent to document.formname.name.value which is pretty cool.
Now, what if I have 2 forms on the page, that same field name "name"?
What would $F return? It does not take
2008 Jul 15
9
Beginner Question.
I''m just getting into RoR, coming from a long PHP background. So far I
LOVE IT!
I''m hitting a roadblock with updating my mysql database. For
simplicities sake, I have 2 tables and here are the relevant columns.
Table Users
id
name
email
Table Issues
id
createdby
assignedto
reportedby
In my models I have everything mapped properly I believe.
When I try to update the
2006 Apr 12
0
Sorting with SQL for has_one, belongs_to relationship
...nrails.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 has_one bar. My HTML table needs to have columns name,
title, and note and need to sort among them.
Is there a way to use sort helper to sort those columns? I''ve looked
at pure javascript solutions but I couldn''t find anything that fully
supports safari.
Thanks.
2006 Aug 17
1
find_by_contents fails with :include option
...in two separate tables, it will be
ambiguous and throw an exception, e.g.
---
Question Load Including Associations (0.000000) Mysql::Error: Column
''id'' in where clause is ambiguous: SELECT foos.`id` AS t0_r0, ...
bars.`id` AS t1_r0, ... FROM foos LEFT OUTER JOIN bars ON bars.foo_id =
foos.id WHERE (id in (1))
REBUILD YOUR INDEX! One of the id''s didn''t have an associated record: 1
---
Error should probably log a better message too...
Quick way to fix it:
313: conditions = [ "#{table_name}.#{connection.quote_column_name(''id'')}
in (...
2012 Mar 19
0
Re: Rails - validate inclusion fails on rake test:integration
Frederick Cheung: "why validate the inclusion at all ? I''d validate the presence of the
foo_id column and use a foreign key constraint to ensure that it can''t
contain junk."
How you''d "use a foreign key constraint"? That is, how do you''d implement the code in order "to ensure that it can''t contain junk"?
--
You received this mes...
2006 May 17
10
HABTM << producing incorrect insert sql ?
Greetings railsers -
I''m trying to add to a collection through HABTM, but the sql
insert is trying to insert a PK rather than letting mysql produce the
auto_increment''ed PK.
## @medication_dose holds a validated, saved model
@medication_dose.medication_frequencies << MedicationFrequency.find
(:all)
The above bails with,
Mysql::Error: #23000Duplicate
2006 Jul 03
6
help!
Hi,
i''m fairly new to ruby on rails, and i know the question at hand may
seem simple at first, but i''m getting really caught up in trying to
understand this and the docs aren''t giving me answer. i actually thought
i knew how the sql commands work (like :include, :conditions, :etc) but
obviously, i don''t.
there are three models M1, M2, M3 joined by a habtam