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

Unable to generate attributes if the model has a non-standard table name #23

Open
ingro opened this issue Jul 2, 2013 · 5 comments
Open

Comments

@ingro
Copy link

ingro commented Jul 2, 2013

I was trying to use this library and found a (possible?) bug.

For various reason I don't have standard table's name and so I used the $table property inside each model to connect it to the right table.

So when I tried to use:
Factory::attributesFor('Pages');
I only got an empty array, and the same with the other available methods.

Further investigation pointed me to the parseTableName method on the Factory class:

protected function parseTableName($class)
{
        return $this->isNamespaced($class)
            ? str_plural(substr(strrchr($class, '\\'), 1))
            : str_plural($class);
}

I'm actually using a workaround, replacing the return value using the getTable method of Eloquent's model, but I don't know if this is the right way to fix it...

@LimeBlast
Copy link

I'm experiencing a similar issue to this (i.e. running Factory::attributesFor('User') returns nothing but an empty array) - although I am using the standard table names for the models.

@LimeBlast
Copy link

UPDATE: Having had a bit of a play myself, I've also found that the issue lies in the parseTableName() function, although my issue was fixed by throwing a strtolower() into the equation:

protected function parseTableName($class)
{
    return strtolower($this->isNamespaced($class)
        ? str_plural(substr(strrchr($class, '\\'), 1))
        : str_plural($class));
}

This, however, obviously doesn't fix @ingro's issue, which I can only imagine being fixed by getting the table name from the model itself - although I'm not sure quite how to go about doing such a thing.

@jamime
Copy link

jamime commented Jul 17, 2013

Pull request #27 should fix both of these issues 😄.

Factory::attributesFor('Pages'); and Factory::attributesFor('pages'); will now use the pages table unless a public $table variable is declared in the model.

@LimeBlast
Copy link

Good stuff, looking forward to it being accepted into the repo 👍

@ekrembk
Copy link

ekrembk commented Aug 11, 2013

I'm experiencing the same problem, too. I create some tables and models in Turkish and parseTableName does not work.

BTW I don't think getTable() is a good solution here. What if the model isn't extending Eloquent? We can't use getTable() then.

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

Successfully merging a pull request may close this issue.

4 participants