Some trickies :-)

a) If I use storage_names[:default] = 'mdl_user', for example, to map
the table with another name, the mapping runs a strange result

irb(main):019:0> class Usuarios; include DataMapper::Resource;
mapping :id, :username; storage_names[:default] = 'mdl_user' ; end
=> "mdl_user"

It seems to works fine :-)

irb(main):020:0> Usuarios.fields
=> [[:id, Integer, {:nullable=>false, :serial=>true, :key=>true}],
[:auth, String, {:nullable=>false, :default=>"manual", :size=>20}],
[:confirmed, TrueClass, {:nullable=>false, :default=>"0"}], ...
[:imagealt, String, {:nullable=>true, :size=>255}], [:screenreader,
TrueClass, {:nullable=>false, :default=>"0"}]]

But fails when I think it map id and username fields:

> Usuarios.get 1
MysqlError: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'FROM `mdl_user` LIMIT 1' at line 1 (mysql_error_code=0001)

b) If the table name is in plural, we have a new problem:

irb(main):006:0> class Mdl_user; include DataMapper::Resource;
mapping :id, :username; end
=> []

Nothing happens. The tricky passes by putting this code:

irb(main):017:0> English::Inflect.plural_word "mdl_user", "mdl_user"

And now, runs very well :-)

irb(main):018:0> class Mdl_user; include DataMapper::Resource;
mapping :id, :username; end
=> [#<Property:Mdl_user:id>, #<Property:Mdl_user:username>]

If I make a dummy test:

irb(main):024:0> Mdl_user.get 1
=> #<Mdl_user id=1 username="guest">


Xavier
--~--~---------~--~----~------------~-------~--~----~
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