Flourish PHP Unframework
This is an archived copy of the forum for reference purposes

Getting related records with non-standard class names

posted by kaerigan 9 years ago

Hello there. I'm just starting out with Flourish and I'm already in need of assistance.

My problem is this: I like to organize my classes the way the Zend Framework does it (i.e My_Awesome_Class = My/Awesome/Class.php) and so I was trying to apply this to my fActiveRecord classes. I have two tables; "users" and "posts", my classes are named Record_User and Record_Post respectively and I have used fORM::mapClassToTable() to configure the classes properly (I think?). Now, here's the code I'm trying to execute:

$u = new Record_User(1); // user already exists
$posts = $u->buildPosts(); // I've already got some posts in the database, too

However, I get the following error:

The class specified, Post, does not appear to be a valid fActiveRecord class

And indeed, "Post" is not a valid class. How can I make ensure that "Record_Post" is used instead and that this results in a collection of posts instead of an error? I've tried all this without adhering to my class naming habits and it works, but that won't do. Also, the classes:

class Record_User extends fActiveRecord {
    protected function configure() {
        fORM::mapClassToTable($this, 'users');
    }
}

class Record_Post extends fActiveRecord {
    protected function configure() {
        fORM::mapClassToTable($this, 'posts');
    }
}

Thanks in advance!

As of right now Flourish does not explicitly support using different notations other than underscore for tables and columns and upper camel case for classes. I'm not sure it ever will since there would be quite a bit of work involved with trying to figure out what syntax should be looked for where.

That said, I think I have seen people using underscores in their classes names in the forum some. Have you tried this?

$u = new Record_User();
$posts = $u->buildRecord_Posts();

That may or may not work.

posted by wbond 9 years ago

I see. I think I tried what you proposed, but it did not work. And even if it did, it is, if I may say so, a rather ugly solution. So I guess I'll either have to conform to the current naming convention or use another ORM.

Perhaps one could add the ability to configure a class name prefix? However, I am not sure this makes sense as none of the Flourish classes use such a system.

Thanks anyway.

posted by kaerigan 9 years ago