Akelos Framework v1 forum archive. This forum is no longer maintained. To report bugs please visit https://github.com/akelos/akelos/issues
    • CommentAuthorjlromero
     
    How Can i connect and scaffold an existing database? I have a postgres database with tables and data, and I want to scaffold them... but when I generate a scaffold for one table it creates another table...
    • CommentAuthormerindol
     

    'generate' command does not create sql tables. 'migrate' command does. If you have a "persons" table you shoud do : php script/generate scaffold person

    Maybe the problem is only the leading "s". You should tell us more about the problem ; or maybe I'm wrong :p

    Best regards.

    • CommentAuthorjlromero
     
    well the database doesn't applies the conventions of the framework, I mean, the tables are in singular, customer instead of customers, when I generate the scaffold it creates another table, and that is not what I want... sorry about my english... Can I scaffold and existing table even if this table doestn applies the conventions? How can I map the table with Active Record?
    • CommentAuthormerindol
     

    I'm still a newbie but I guess the table name convention is mandatory. Is it hard to change you tables names ?

    Wait for an experimented Akelos user response.

    • CommentAuthorsuthern
     

    Depending on how many tables you have, you may want to re create your database using the Akelos convention.

    For example, if you have a table named 'customer' with specific fields, then what you should do is create a new table called 'customers' with all the same fields. It shouldn't be too hard to copy all the entries from one table into another, depending on what program you are using to manage your database.

    • CommentAuthorjlromero
     
    ok thank you
    • CommentAuthorsuthern
     
    What I meant is to recreate it inside the *model_name*_installer.php file, then run the regular script migrate and scaffold commands.

    THEN copy over the data from the old table to the new. ;-)
    • CommentAuthorgizmo
     
    AFAIK, you can remap table and primary key linked to your model with the setTableName() and setPrimaryKey() methods, which are defined in AkActiveRecord (the class extended by your akelos model objects). This was my personal workaround for making things work with an existing DB:

    1. Cloned my tables (only the structure) with accurate, "akelossly-correct" names :-);
    2. Generated my scaffolds;
    3. Remapped the tables within my model objects with setTableName() and setPrimaryKey();
    4. Deleted the temporary tables.

    In this way i get _form templates working with all the correct fields in their place, and have my listing pages reporting all the records of my pre-existing tables. Ok, i'm actually encountering problems with listing pages - i get my records (with actual record count) but fields within tables are not set correctly - but ain't it a step forward? :-)
    • CommentAuthorjlromero
     
    but I mean, there's got to be a way to do that, if somebody's going to set up an application over an existing database... it's not worthy to re-design the database...
    • CommentAuthorgizmo
     
    There should be a way to specify a custom table name when generating the scaffold. This is probably not so "pure" in MVC philosophy, but it's definitely useful.
    (jlromero: there's actually no need to redesign your DB, if you can remap table names. I've solved 10 minutes ago the problem with listing pages - tomorrow I'll send a bug report - and everything seems to work now).
    • CommentAuthorKaste
     

    Actually you could generate the model

    script/generate model Person
    

    Then edit the Model

    class Person
    function __construct()
    {
        $this->setTableName('person'); #instead of people!
        $this->init(func_get_args());
    }
    

    Now scaffold the model

    script/generate scaffold Person
    
    • CommentAuthorjlromero
     
    gizmo that is exactly what I need to do...
    • CommentAuthorjlromero
     
    Kaste I actually did that, but when I wanted to display, lets say, the description of table state(s), it display the route of the action... very messy...
    • CommentAuthorKaste
     

    romero, exactly what are you trying to do?

    I think if someone could contribute an 'Active Scaffold' that would be great. Right now scaffolding an existing model is the way to go IMHO. Keep in mind to modify the templates if you're about to scaffold a lot.