Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"cake bake fixture all" could not find correct table name #5377

Closed
ericj opened this issue Dec 10, 2014 · 8 comments
Closed

"cake bake fixture all" could not find correct table name #5377

ericj opened this issue Dec 10, 2014 · 8 comments

Comments

@ericj
Copy link

ericj commented Dec 10, 2014

  1. In CakePHP 2.5.x, FixtureTask.php function all(), it will read all tables from database connection, even the model file .php not exists. I think this is in-consist with the comment "Bake All the Fixtures at once. Will only bake fixtures for models that exist." ?
  2. In CakePHP 2.5.x, FixtureTask.php function bake(), if the model file exists and defines the $useTable variable, this function will not use it, instead it will always use "Inflector::tableize" with model name.

In my use case, if you want to "bake fixture all" at once, if there are many tables in your database which are not follow the table naming convention, the bake fixture all will fail, because of the error "Could not find your selected table "

I think for all() function in FixtureTask, we should only bake fixtures with model file exists? and if the $useTable variable defined in model file, then we should bake fixture from the defined table name.

By doing this, we can easily create model fixtures for existing project more easily.
How do you think?

@markstory
Copy link
Member

Fixtures should be independent of the models imo. I think the documentation is wrong and should probably be updated as well. The issue with only baking fixtures for models, is that when baking a model + fixture, the model won't exist yet

@markstory markstory added this to the 2.5.8 milestone Dec 10, 2014
@ericj
Copy link
Author

ericj commented Dec 11, 2014

Hi markstory,
Thanks, now I understand the design consideration for "bake fixture all" behavior.
Per your saying, it seems like current "bake fixture all" behavior is correct, since CakePHP will read all tables from database connection regardless model .php file exists or not.

Here I have a use case:

In an existing project there are no any unit test cases before, and there are many tables. Some table name not follow CakePHP conventions and not using plural. And some are just exists in database and not used by any Model. Those using tables are well defined in model .php file.

In this case, when using "bake fixture all", it will fail because of table name is incorrect. That's because CakePHP will bake fixtures for all tables and read from "Inflector:: tableize" name
which might different than real table name existing in database.

This situation let me confused, is this the intension that "bake fixture all" intent to help?
We need fixtures to test models, and hope there is one way to quickly auto create fixtures for our testing target, model. But current "bake fixture all" behavior is creating fixtures independently from model which blocks me to create fixtures for an working project even it's not 100% follow CakePHP conventions.

So, what do you think on automatically creating fixtures for testing model? And how to make it more flexible for the existing project?

@markstory
Copy link
Member

This situation let me confused, is this the intension that "bake fixture all" intent to help?

bake fixture all like all features of bake works best when the database tables follow the conventions. If your tables don't the output will not be ideal. If you are getting fixtures for tables you don't need, just delete the generated files 😄

@ericj
Copy link
Author

ericj commented Dec 11, 2014

I also hope things can be that easy, but the reality is "cake bake all" will stop when it tries to create fixture for the table name which not follow the convention :(

@markstory
Copy link
Member

Do you have a table definition that bake has issues with? I can update bake to skip/work through the problems.

@ericj
Copy link
Author

ericj commented Dec 11, 2014

Hi Mark,

I think we just need to create a table in database with name not in plural, for example: "user"
Then run "cake bake fixture all".
The error will show "Error: Could not find your selected table users"

@markstory
Copy link
Member

Thanks, I'll try reproducing 😄

@markstory markstory self-assigned this Dec 11, 2014
markstory added a commit that referenced this issue Dec 16, 2014
When a table is missing print a warning to stderr but don't exit. This
allows people to use `bake fixture all` with non-conventional tables.

Refs #5377
@markstory
Copy link
Member

Closing as #5422 is open now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants