Raimon,
I suspect that your relationship column (foreign key) should actually be
called _*group_id*_ not *list_*group_id like in:
def self.up
create_table :list_groups, :force => true do |t|
t.string :name
end
create_table :list_people, :force => true do |t|
t.integer :group_id, :null => false
t.string :username
end
Philippe
On 6/25/2010 2:39 AM, Raimon Fernandez wrote:
Hi, it's me again ...
:-)
I have one table called people and another one called groups.
Each person from people belongs to ONE group.
module List::Models
class Person< Base
belongs_to :group
end
class Group< Base
end
end
When I get all persons from people, I expect, like in RoR, the access to
related records, like:
module List::Views
def people(xml)
xml.posts do
@posts.each do |person|
xml.person do
xml.id(person.id)
xml.name(person.name)
xml.surname_01(person.surname_01)
xml.surname_02(person.surname_02)
xml.has_come(person.has_come)
xml.group(person.group.name) # Here I'm asking for related
information about the group name
end
end
end
end
end
and I'm getting => NoMethodError at /people/list undefined method `name' for
nil:NilClass
also, I'm trying to test it on Console:
MacBook-ProII-2:Test montx$ camping -C list.rb
** Starting console
Person.find(1)
NameError: uninitialized constant Person
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:443:in
`load_missing_constant'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in
`const_missing'
from
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:92:in
`const_missing'
from (irb):1
but it seems that the model hasn't been loaded ...
thanks again for your help,
regards,
r.
ps. yes, I have in the db the relation between two tables: list_group_id in the
list_people table.
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list
_______________________________________________
Camping-list mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/camping-list