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

table and columns names #2

Closed
bystac opened this issue Dec 7, 2010 · 2 comments
Closed

table and columns names #2

bystac opened this issue Dec 7, 2010 · 2 comments

Comments

@bystac
Copy link

bystac commented Dec 7, 2010

Assume the following tables:
minisites {
id
campaign_id
title
}

campaigns {
   id
   title
}

Assume a declared the NotORM_Structure_Convention:
$structure = new NotORM_Structure_Convention("id","%s_id","%ss");

NotORM still can't get it right, or am I missing something?

$_minisites = $nORM->minisites($criteria);
foreach ($_minisites as $m) {
    print $m['title'].'|';
    print $m->campaigns['title'].'|'; // wrong,
    print $m->campaign['title'].':'; // wrong,
}
// NOTORM try to access the campaigns_id which is wrong

Any ideas how to make it work?

@bystac
Copy link
Author

bystac commented Dec 7, 2010

OK, 2 things need be done here:

  1. proper inflector singular/plural functions
  2. when joining automatic prepend tablename to avoid ambiguous fields errors,

Here how I solved it:
$res = $_minisites->select('minisites.id, minisites.title, campaigns.title')->fetch();

And override the Structure class:

class My_NotORM_Conversion extends NotORM_Structure_Convention {
function __construct() {
    $this->primary = 'id';
    $this->foreign = '%s_id';
    $this->table = '%s';
}
function getReferencedColumn($name, $table) {
    if ($this->table != '%s' && preg_match('(^' . str_replace('%s', '(.*)', preg_quote($this->table)) . '$)', $name, $match)) {
        $name = $match[1];
    }

    $inflector = new Inflect();
    $name = $inflector->singularize($name);
    return sprintf($this->foreign, $name, $table);
}
}

will be waiting for official solution.

@vrana
Copy link
Owner

vrana commented Dec 7, 2010

$m->campaign['title'] works for me with your database structure and your $structure.

This issue was closed.
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

No branches or pull requests

2 participants