[Nitro] OG automatically adding Foreign Key constraints

Isaac Devine Isaac at chiptech.co.nz
Tue Nov 29 15:15:01 EST 2005


On Tue, 2005-11-29 at 14:47 +0000, Tim Larson wrote:
> On Tue, Nov 29, 2005 at 02:43:49PM +0000, Tim Larson wrote:
> > On Tue, Nov 29, 2005 at 03:47:26PM +1300, Isaac Devine wrote:
> > > When using belongs_to and has_many Og isn't generating Foreign Key
> > > Constraints :
> > > 
> > > class Example1
> > >  property :name, String
> > >  has_many :children, Example2
> > > end
> > > 
> > > class Example2
> > >  property :address, String
> > >  belongs_to :parent, Example1
> > > end
> > > 
> > > What am I doing wrong? 
> > > Failing that is there a way I specify the constraints?
> > 
> > Because the relation name ":children" does not match the name of
> > the related class "Example2" Og is getting lost...change your
> > "has_many" line like this to give it the clue it needs:
> >   has_many :children, Example2, :foreign_name => :parent
> 
> I think my explanation was wrong...the problem is because the name of
> relation ":children" does not match the name used in the belongs_to
> relation ":parent", but you probably figured that out from the example
> has_many line above.
> 

Still doesn't work. FWIW I am using postgres and the Debug output is as
follows (added a line to output the generated sql in psql.rb):

D, [2005-11-30T08:46:30.383009 #6720] DEBUG -- : Og manageable classes:
[Example2, Example1]
D, [2005-11-30T08:46:30.408267 #6720] DEBUG -- : Generated sql:
CREATE TABLE ogexample2 (parent_oid integer, address text, oid serial
PRIMARY KEY) WITHOUT OIDS;
NOTICE:  CREATE TABLE will create implicit sequence "ogexample2_oid_seq"
for "serial" column "ogexample2.oid"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"ogexample2_pkey" for table "ogexample2"
I, [2005-11-30T08:46:30.456938 #6720]  INFO -- : Created table
'ogexample2'.
D, [2005-11-30T08:46:30.479274 #6720] DEBUG -- : Generated sql:
CREATE TABLE ogexample1 (name text, oid serial PRIMARY KEY) WITHOUT
OIDS;
NOTICE:  CREATE TABLE will create implicit sequence "ogexample1_oid_seq"
for "serial" column "ogexample1.oid"
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index
"ogexample1_pkey" for table "ogexample1"
I, [2005-11-30T08:46:30.493831 #6720]  INFO -- : Created table
'ogexample1'.

thanks,
Isaac




More information about the Nitro-general mailing list