I'm trying to attach Datamapper to a middleman object of mine that
wont be persisting anything, but would be useful to hook into a web
form that does validations. Upon it's custom save, it would would
build a bunch of other objects. Running into all kinds of problems
however.

What's the best way to create a datamapper model without a persistance
layer?

Here's what I've tried so far:

-----
Using abstract:

    DataMapper.setup(:abstract, "abstract::")
    class Employer
      include DataMapper::Resource

      property :name, String
      validates_present :name


      def self.default_repository_name
        :abstract
      end

    end

FAILS with error:
DataMapper::IncompleteModelError: Employer must have at least one
property or many to one relationship to be valid

-----
Using sqlite3 inmemory:

    DataMapper.setup(:memory, "sqlite3::memory:")
    class Employer
      include DataMapper::Resource

      property :name, String, :key => true
      validates_present :name


      def self.default_repository_name
        :memory
      end

    end

FAILS with error:
DataMapper::IncompleteModelError: Employer must have at least one
property or many to one relationship to be valid


-----
Using just validate (works, kindof):

    class Employer
      include DataMapper::Validate

      attr_accessor :name
      attr_accessor :company
      validates_present :name

    end


This is what I ended up using, however it sucks since I don't have
access to the Datamapper builder methods (attributes= etc). So I have
to assign each accessory manually. We should think about making these
datamapper accessors methods a module so people can include them ala
cart


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to