Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > define relationschip external database-scheme

Reply
Thread Tools

define relationschip external database-scheme

 
 
Remco Zwaan
Guest
Posts: n/a
 
      03-06-2008
Hi,

i want to use or external database for my rails app. The connention to
the external database(no-rais-app) works fine, but how must i define the
relationship between this tabels (if possibly no change in the table
scructure)

The external database-scheme:

CREATE TABLE `bestemmingen` (
`bestemming_id` char(3) NOT NULL default '',
`naam` varchar(50) default NULL,
`naam_en` varchar(50) default NULL,
`landcode` char(2) default NULL,
`airport_name` varchar(100) default NULL,
`alt_naam` varchar(50) default NULL,
`dist_ams` decimal(6,1) default NULL,
`stad_zoeknaam` varchar(50) NOT NULL default '',
PRIMARY KEY (`bestemming_id`),
KEY `land_id` (`landcode`),
KEY `stad_zoeknaam` (`stad_zoeknaam`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Bestemming iatacode en
iso bestand';

CREATE TABLE `landen` (
`landcode` char(2) NOT NULL default '',
`naam` varchar(50) NOT NULL,
`naam_en` varchar(50) NOT NULL,
`alt_naam` varchar(200) NOT NULL,
`landafk` char(3) default NULL,
`land_zoeknaam` varchar(100) NOT NULL default '',
PRIMARY KEY (`landcode`),
KEY `land_zoeknaam` (`land_zoeknaam`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Landen opzoek tabel';


Grtz..remco
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Jano Svitok
Guest
Posts: n/a
 
      03-06-2008
On Thu, Mar 6, 2008 at 9:04 AM, Remco Zwaan wrote:
> Hi,
>
> i want to use or external database for my rails app. The connention to
> the external database(no-rais-app) works fine, but how must i define the
> relationship between this tabels (if possibly no change in the table
> scructure)
>
> The external database-scheme:
>
> CREATE TABLE `bestemmingen` (
> `bestemming_id` char(3) NOT NULL default '',
> `naam` varchar(50) default NULL,
> `naam_en` varchar(50) default NULL,
> `landcode` char(2) default NULL,
> `airport_name` varchar(100) default NULL,
> `alt_naam` varchar(50) default NULL,
> `dist_ams` decimal(6,1) default NULL,
> `stad_zoeknaam` varchar(50) NOT NULL default '',
> PRIMARY KEY (`bestemming_id`),
> KEY `land_id` (`landcode`),
> KEY `stad_zoeknaam` (`stad_zoeknaam`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Bestemming iatacode en
> iso bestand';
>
> CREATE TABLE `landen` (
> `landcode` char(2) NOT NULL default '',
> `naam` varchar(50) NOT NULL,
> `naam_en` varchar(50) NOT NULL,
> `alt_naam` varchar(200) NOT NULL,
> `landafk` char(3) default NULL,
> `land_zoeknaam` varchar(100) NOT NULL default '',
> PRIMARY KEY (`landcode`),
> KEY `land_zoeknaam` (`land_zoeknaam`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COMMENT='Landen opzoek tabel';


(excuse my lack of Dutch

class Land < ActiveRecord::Base
set_table_name "landen"
has_many :bestemmingen, :class_name => "Bestemming" # land_id will be guessed
end

class Bestemming < ActiveRecord::Base
set_table_name "bestemmingen"
belongs_to: :land # land_id will be guessed
end

Note: Next time try to ask directly on rails google group, you'll get
much better answer there.
Note 2:I haven't worked with rails for a long time, so take this as a
direction, not ready code.
Note 3:You can find all this on api.rubyonrails.com, in the part about
ActiveRecord.

Jano

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
About typedef -- define the function pointer or define function model? robin liu C Programming 3 04-21-2006 03:26 PM
#define _ and #define __ Brian Takita Ruby 0 01-23-2006 04:34 AM
#define and external static Fan Zhang C Programming 8 10-14-2004 11:50 AM
unresolved external symbol/using an external dll Scott Allen C++ 8 05-02-2004 06:11 PM
How to define a define that defines some defines ? theotyflos C Programming 3 02-19-2004 05:07 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57