🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: pl.comp.lang.ruby
Article #1139

belongs_to do unique key

#1139
From: FOX
Date: Tue, 26 Aug 2008 19:58
47 lines
1722 bytes
Witam

Mam taki problem z niestandardową konwencją powiązań tabal.
Jak można zdefiniować inne niż domyślne
zachowanie belongs_to do klucza unikalnego a nie głownego.

Oto konkretny przypadek 2 tabel

tabela 1 (waluty):

currencies (
   id        int      - PK
   currency  char(3)  - UK
   name      text
   format    text
)


tabele 2 (kursy):

exchanges (
   id        int      - PK
   currency  char(3)  - FK do currencies(currency)
   date      date
   course    number(10,4)
)



class Currency < ActiveRecord::Base
   has_many :exchange
end

class Exchange < ActiveRecord::Base
   belongs_to :currency,  :foreign_key => ...........
       :conditions => '"exchanges".currency = "currencies".curency'
end


i tutaj w miejsce kropek przydałoby się jakieś
wyłączenie domyślnego zachowania foreign_key

lub może jest jakaś magiczna funkcja którą należałoby nadpisać dla klasy 
Exchange.

Pozdrawiam
FOX
Technical Details
Message-ID: <g91nbj$cc7$1@atlantis.news.neostrada.pl>
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mail

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!newsfeed.gazeta.pl!newsfeed.neostrada.pl!atlantis.news.neostrada.pl!news.neostrada.pl!not-for-mail
From: FOX <user@company.xx>
Newsgroups: pl.comp.lang.ruby
Subject: belongs_to do unique key
Date: Tue, 26 Aug 2008 21:58:38 +0200
Organization: TP - http://www.tp.pl/
Lines: 47
Message-ID: <g91nbj$cc7$1@atlantis.news.neostrada.pl>
NNTP-Posting-Host: nat5.tychy.msk.pl
Mime-Version: 1.0
X-Trace: atlantis.news.neostrada.pl 1219780787 12679 213.77.86.5 (26 Aug 2008 19:59:47 GMT)
X-Complaints-To: usenet@news.neostrada.pl
NNTP-Posting-Date: Tue, 26 Aug 2008 19:59:47 +0000 (UTC)
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit