I'm trying to use Datamapper in my Rails 3.1 application and I'm having trouble mapping models that exist on a 2nd repository.
I have the following class
class Arp
include DataMapper::Resource
storage_names[:passive] = "arp"
property :id, Serial, :field => "id"
property :ip_address, String, :field => "ipaddr"
def self.default_repository_name
:passive
end
end
There are some more fields but for the sake of simplicity I commented them out and got the same error. Here's what I get when i run rake db:migrate:
Arp must have at least one property or many to one relationship to be valid
Not sure what's going on because I clearly have a property defined.
Here's the table sttucture from mysql
+--------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| ipaddr | varchar(15) | NO | | NULL | |
+--------+-------------+------+-----+---------+----------------+
Again a few fields removed for clarity.
I have the multiple repositories in my database.yml file in rails and I set them up based on the guide on the dm-rails github page.
Here's a shortened version of that file.
passive_defaults: &passive_defaults
adapter: mysql
username: <USERNAME GOES HERE>
password: <PASSWORD GOES HERE>
host: localhost
database: passive
development:
database: portal
<<: *portal_defaults
repositories:
passive:
<<: *passive_defaults
Anyone see what I'm doing wrong here? Thanks.
I solved this shortly after asking the question.
The order of the self.default_repository_name override mattered. So
class Arp
include DataMapper::Resource
def self.default_repository_name
:passive
end
storage_names[:passive] = "arp"
property :id, Serial, :field => "id"
property :ip_address, String, :field => "ipaddr"
end
works.