On Aug 27, 10:52 pm, Xavier Belanche <[EMAIL PROTECTED]> wrote:
Hello, many thanks for your report.
I'll add more types for MySQL according to MySQL manual in next
release.
> irb(main):019:0> class Usuarios; include DataMapper::Resource;
> mapping :id, :username; storage_names[:default] = 'mdl_user' ; end
> => "mdl_user"
I think the problem here is the order between storage name setup and
mapping matters. The working flow of mapping is something like:
1. connect to database with adapter created previously.
2. do a sql query to retrieve fields with the default storage.
3. find a match or matches with arguments you passed in.
4. if any match found, do a property call for your model.
5. else, ignore all.
Here you called mapping first, so dm-mapping couldn't find the correct
table.
Then there's no mapping created, even the storage name was provided
later.
> 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"}]]
This would create another sql to query fields, so this would work.
> 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)
I think this was because the primary key didn't setup correctly.
That was because mapping failed, no primary key was setup.
Perhaps I should provide some workaround with this issue.
I can imagine two solutions currently:
1. when no mapping created, raise an exception.
2. when storage name changed, discard all mapping created previously.
then recall all mapping called previously, call them once again.
Solution one would force you to setup table name before creating any
mapping.
Solution two would allow you to change table name on the fly, then you
can
switch any table at any time.
What do you think about this issue?
Thanks for your help once again, cheers,
Lin Jen-Shin
> 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
-~----------~----~----~----~------~----~------~--~---