Thread View: pl.comp.lang.ruby
2 messages
2 total messages
Started by FOX
Tue, 26 Aug 2008 21:58
belongs_to do unique key
Author: FOX
Date: Tue, 26 Aug 2008 21:58
Date: Tue, 26 Aug 2008 21:58
48 lines
950 bytes
950 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 19:25
Date: Tue, 17 Feb 2009 19:25
32 lines
794 bytes
794 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