Welcome Guest, Not a member yet? Register   Sign In
Can't find table in datamapper 1.8.1 [solved]
#1

[eluser]phranx[/eluser]
Hey guys,
first of all I'd like to thank Wan and all the guys who contribuited to this library: I can write code faster and, without the pain of filtering results sets I'm also healthier Smile

However, I got a problem with table names on my 2 environments.

I was able to configure datamapper to work on my local server:
I got a users table, and a groups table (with a N:1 relation). Both tables are named in lower-case
I edited the provided _template class to match my relationship schema and the application works perfectly.

Then I put all my files on my kodingen account and I set up the database config file properly, but when I try to list the groups I got this

Quote:Error Number: 1146
Table 'my_kodingen_db_name.Groups' doesn't exist

So... it seems that datamapper is looking for a capitalized table name... and infact I tried to rename the table into Groups and it works.

Have you got any advice for this odd behaviour?

Thanks in advance
Francesco
#2

[eluser]WanWizard[/eluser]
When you don't specify a table name in the model, the table name is determined using
Code:
$this->table = plural(get_class($this));

plural() is a function in the inflector helper included in the Datamapper distribution that does an strtolower(), so it can't be uppercase. I've checked CI's inflector helper, but that does a conversion to lower case as well (in 2.0.2).

Maybe check what inflector helper you've got installed, and what the result of plural('TEST') is (should be 'tests')?
#3

[eluser]phranx[/eluser]
[quote author="WanWizard" date="1310225300"]When you don't specify a table name in the

Maybe check what inflector helper you've got installed, and what the result of plural('TEST') is (should be 'tests')?[/quote]

Thank you Wan. You solved the problem.
I didn't use the inflector helper provided with the datamapper. I don't use any inflector at all... or at least not explicitly.

The native CI inflector (version 2.0.2) doesn't strtolower the input string.

Code:
echo plural('TEST'); //outputs TESTs.

However it's strange the different behaviour between the 2 environments.
The code is essentially the same: the differences are limited to the db connection parameters and the base_url.... :-S
#4

[eluser]WanWizard[/eluser]
Datamapper will do a $this->load->helper('inflector').

If the Datamapper version is not present in application, the default CI version will be loaded from system. If both codebases are the same, and both platforms are the same, you should have had this issue in development as well.

If you develop on Windows, you might have bumped into the fact that MySQL is not case sensitive when it comes to table names.
#5

[eluser]phranx[/eluser]
[quote author="WanWizard" date="1310309204"]
If you develop on Windows, you might have bumped into the fact that MySQL is not case sensitive when it comes to table names.[/quote]

huu? I didn't know that. So this should cause the different behaviour.
Thank you Wan
#6

[eluser]WanWizard[/eluser]
The Windows file system isn't case sensitive, and as MySQL stores it's tables as files, the table names aren't case sensitive either. On a *nix platform however, they are.

You can force MySQL to use lower case only by setting 'lower_case_table_names' to 1 in my.cnf, which will always create tables in lower case, and makes the table name case insensitive.




Theme © iAndrew 2016 - Forum software by © MyBB