* Removed lines of Artistic License 1.0 encumbered,
[merb_mart.git] / app / models / address.rb
blob0e1ffbb63ad10b45f69dfb1bc568d39597b7f2ca
1 require 'validate'
3 class Address
4   
5   include DataMapper::Resource
6   include DataMapper::Validate
7   
8   one_to_one  :order
9   many_to_one :order_user
10   many_to_one :country
11     
12   property :first_name, String, :length => 50, :nullable => false
13   property :last_name,  String, :length => 50, :nullable => false
14   property :telephone,  String, :length => 20
15   property :address,    String,                :nullable => false
16   property :city,       String, :length => 50
17   property :state,      String, :length => 30
18   property :zip,        String, :length => 10 
19   
20   # Validation
21   validates_presence_of :order_user_id, :country_id
22   validates_presence_of :zip, :message => "#{ERROR_EMPTY} If you live in a country that doesn't have postal codes please enter '00000'."
23   validates_presence_of :telephone, :message => ERROR_EMPTY
24   validates_presence_of :first_name, :message => ERROR_EMPTY
25   validates_presence_of :last_name, :message => ERROR_EMPTY
26   validates_presence_of :address, :message => ERROR_EMPTY
27   
28   validates_length_of :first_name, :maximum => 50
29   validates_length_of :last_name, :maximum => 50
30   validates_length_of :address, :maximum => 255
31   
32 end