Hi everyone,
I''m having a bit of difficulty wrapping my head around this schema.
Basically there are no ''normal'' foreign key. It''s
all text...
PACKAGES
----------------
PKGPATH (primary key)
NAME
DESCRIPTION
CATEGORIES
-----------------
NAME
PKGPATH (sort of foreign key that references table PACKAGES)
P.S. Yes everything is in CAPS
And now I''m trying to fit this in active record...
Now a simple :foreign_key => ''PKGPATH'' doesn''t
work because the
generated SQL tries to match it to an ''id'' column:
class Package < ActiveRecord::Base
belongs_to :category, :foreign_key => ''PKGPATH''
end
When I do ruby script/console:
p = Package.find(:first) <=== OK
p.category <==== NOT OK
p.category generates the following SQL: SELECT * FROM categories WHERE
(categories.id = ''archivers/arc'') LIMIT 1
I was thinking either of using :conditions on the belongs_to side and
finder_sql on the has_many side...but up until now
belongs_to->:conditions tells me that the constant PKGPATH is
uninitialized... :(
Here''s what I tried with the :condition
class Port < ActiveRecord::Base
belongs_to :category, :foreign_key => ''PKGPATH'',
:conditions =>
''categories.PKGPATH = #{PKGPATH}''
end
Any help would be greatly appreciated...
JD
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---