ruby on rails - has_many and a legacy scheme -
I'm looking for advice here:
I have two tables in heritage plan, Code> one and b
, asamename = b. Name brought to
. If both of them are columns, then how do I establish a relationship between them in Rail (v2.1.0)? Given that there are many b
in A
, what would be best practice:
-
use
: finder_sql < / Code> and just select a SQL,
-
Configure the connection through other parameters (how? I know that I have the
: foreign_key = 'alias' / Code>, but it will only try to set a name to
AID = B.
relationship - what can I do to set right?), < Li
So, what would you suggest?
If you are stuck with Rail 2.1 for some reason, then the best option is set_primary_key It looks like
, such as:
class is a set_primary_key's 'somename' has_many: bs ,: foreign_key = & gt; The 'alias' end
also has a nickname that allows you to use syntax such as attribution for that ( self.primary_key = 'somename'
).
By the way, if you are able to upgrade to 2.3, you can use the primary_key
option directly with has_many
, such as: < / P> is_imit: debitosis,: primary_keys = & gt; 'Somename' ,: foreign_key = & gt; If you choose to use it, you will not need to declare the primary key for the class using the
set_primary_key
.
Comments
Post a Comment