[Nitro] How do I use create_constraints

Kashia Buch kashia at vfemail.net
Mon Apr 3 17:47:37 EDT 2006


Hi,

>> class Dbfile
>>   property :filename, String
>>   belongs_to  :dbdir, Dbdirectory
>> end

Single constraints like unique:

class Dbfile
   property :filename, String, :unique => true
   # .. etc
end

>> How do I use create_constraints to create a unique constraint for
>> (filename, dbdir)?

I don't know about general constraint creation...

But, keep in mind that you should handle errors as well:

class Dbfile
   # props etc

   validate_unique :filename
   validate_unique :dbdir

   # maybe something like that too?
   validate_format :filename, :format => /[^\/]+/
end

In controller:

def create_dbfile(blabla)
   obj = Dbfile.new('asdf.pdf', Dbdirectory[1])
   if obj.valid?
     obj.save!
   end
   # else do something
end

> I think that if you use the postgres store that they are created
> automatically. I don't believe the other stores do, though I suppose
> Mysql could now.

Postgres for sure... not sure about mysql..

Hope that helps,

Kashia

-- 
Feel the love
http://pinkjuice.com/pics/ruby.png



More information about the Nitro-general mailing list