Hello All. I need to connect to an older db that doesn't follow the
rails naming structure. I can establish a connection ok and read data
but am unable to join two tables together within that database.
This is what I have:
Legacy DB tables:
-----------------------------------------------------------
mysql> describe frk_project;
+-------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------------+------+-----+---------+----------------+
| projectId | mediumint(8) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(120) | NO | | | |
| description | text | NO | | | |
+-------------+-----------------------+------+-----+---------+----------------+
mysql> describe frk_item;
+------------------+-----------------------+------+-----+------------+----------------+
| Field | Type | Null | Key |Default|Extra
+------------------+-----------------------+------+-----+------------+----------------+
| itemId | int(10) unsigned | NO | PRI | NULL |auto_increment
| projectId | mediumint(8) unsigned | NO | MUL | 0
| title | varchar(255) | NO | |
| description | text | NO | |
Rails Models:
-----------------------------------------------------------
class Freak_Item < ActiveRecord::Base
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:encoding => "utf8",
:username => "root",
:database => "taskfreak",
:socket => "/var/lib/mysql/mysql.sock"
)
self.table_name = 'frk_item'
self.primary_key = 'itemId'
belongs_to :freak_project
end
-----------------------------------------------------------
class Freak_Project < ActiveRecord::Base
ActiveRecord::Base.establish_connection(
:adapter => "mysql",
:encoding => "utf8",
:username => "root",
:database => "taskfreak",
:socket => "/var/lib/mysql/mysql.sock"
)
self.table_name = 'frk_project'
self.primary_key = 'projectId'
has_many :freak_items, :foreign_key => "projectId"
end
-----------------------------------------------------------
Am I missing something in the models ?
Thanks, any help appreciated...Bill
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---