Thread View: pl.comp.lang.ruby
2 messages
2 total messages
Started by FOX
Tue, 26 Aug 2008 19:58
belongs_to do unique key
Author: FOX
Date: Tue, 26 Aug 2008 19:58
Date: Tue, 26 Aug 2008 19:58
47 lines
1722 bytes
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
Re: belongs_to do unique key
Author: Zbyszek Malec
Date: Tue, 17 Feb 2009 18:25
Date: Tue, 17 Feb 2009 18:25
31 lines
1562 bytes
1562 bytes
Dnia Tue, 26 Aug 2008 21:58:38 +0200, FOX napisał(a): > 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 Nie mam jakiegoś większego doświadczenia z ActiveRecord, więc jak bym głupoty pisał, to liczę że mnie ktoś poprawi. class Currency < ActiveRecord::Base has_many :exchange, :primary_key => 'currency', :foreign_key => 'currency' end class Exchange < ActiveRecord::Base belongs_to :currency, :foreign_key => 'currency' end I jak? -- Zbyszek Malec gg 2756100
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads