Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Error: Unknown column 't0.' in 'where clause' ... : using oil ...scaffold with --orm switch
  • Reposted from http://fuelphp.com/forums/topics/view/5691/ I'm trying to use oil with orm instead of Model_Crud on a totally by-the-book fresh install of fuelphp on Snowleopard MAMP with php 5.3. The MAMP stack virtually-hosts plenty of other php-based dev websites and blogs with no errors, so I'm assuming the environment's OK. oil scaffolding works perfectly if I don't use the --orm switch at scaffold time. I've zeroed and reinstalled the default fuel application from scratch several times, copied and pasted the oil+orm scaffolding code from the docs page:
    oil g scaffold post title:varchar[50] body:text user_id:int --orm
    

    ...and still get the same ... Unknown column 't0.' in 'where clause' ... error: when I try to view http://.../posts:
    Fuel\Core\Database_Exception [ Error ]: SQLSTATE[42S22]: Column not found: 1054 Unknown column 't0.'
    in 'where clause' with query: "SELECT `t0`.`title` AS `t0_c0`, `t0`.`body` AS `t0_c1`, `t0`.`user_id` 
    AS `t0_c2` FROM `posts` AS `t0` WHERE `t0`.`id` = '0' OR ((`t0`.`` IS null)) LIMIT 1"
    

    COREPATH/classes/database/mysql/connection.php @ line 210
    

    The backtrace is as follows:
    COREPATH/classes/database/query.php @ line 240
    PKGPATH/orm/classes/query.php @ line 901
    PKGPATH/orm/classes/query.php @ line 959
    PKGPATH/orm/classes/model.php @ line 424
    PKGPATH/orm/classes/model.php @ line 545
    APPPATH/classes/controller/frocks.php @ line 8
    APPPATH/classes/controller/frocks.php @ line 8
    COREPATH/classes/request.php @ line 443
    DOCROOT/index.php @ line 38
    

    My "Post" model specifies:
    protected static $_properties = array('title', 'body', 'user_id');
    

    I've also tried specifying:
    protected static $_properties = array('id', 'title', 'body', 'user_id');
    

    and
    protected static $_properties = array('id', 'title', 'body', 'user_id', 'updated_at', 'created_at');
    

    with effectively identical results. My config/DEVELOPMENT/db.php is as follows:
    'connection' => array(
    'dsn' => 'mysql:host=localhost;dbname='mypersonal_fuel_dbname',
    'username' => 'mypersonal_fuel_dbuser',
    'password' => 'mypersonal_fuel_password',
    

    I've also tried specifying 'mysql' (and database name) instead of 'pdo' in the main config/db.php file. The results are indistinguishable. Help greatly appreciated. -Ben.
  • The migration script had been run; there's definitely a table present in the original error. If you run:
    oil g scaffold foo title:varchar[50] body:text user_id:int --orm
    

    And then attempt to load http://{sitename}/foo without running the
    refine...
    
    statement afterwards, you're warned explicitly that the table's missing.
    E.g. result:
    Fuel\Core\Database_Exception [ Error ]: SQLSTATE[42S02]: Base table or view not found:
     1146 Table 'fuelstationwagon.sw_foos' doesn't exist with query: "SELECT `sw_foos`.* FROM `sw_foos`" 
    

    Ta for trying to help though. I've now switched to the 1.1dev branch and am having better luck.
  • That said, I've just tested the command above - with the --orm switch - again and it's still generating a model that extends Model_Crud, not Orm\Model To reiterate: "scaffold" seems to ignore the --orm switch entirely, even if you create the model previously using oil --orm. E.g.
    oil g model foo title:varchar[50] body:text user_id:int --orm
    
    generates a "foo" model using Model\orm as expected. Then running:
    php oil g scaffold --orm foo
    
    throws the expected error:
    "Error: /..PATH.../fuel/app/classes/model/foo.php already exists, use -f or --force to override." Forcing the override just overwrites the ORM model with a CRUD model What am I missing here?
  • I don't know if this is the exact same error but in the controller if you change
    Model_Name::find_all
    
    to
    Model_Name::find('all');
    
    it seems to work. The ORM model doesn't have a find_all function like the CRUD model does for some reason. I hope that's your problem as I did the same thing in changing from CRUD to ORM and was getting the same error with action_index()
  • If this means the wrong code is generated in orm mode, please create an issue for this on http://github.com/fuel/oil/issues. Bug reports in the forums will be easily missed...
  • As a newbie (2 days now), to another newbie, it almost looks like you never ran the refine migrate command after specifying the table structure. Have you tried to run the migrate script? If so does it produce a result? Does the database definitely have the table structure in place? Running
    oil g scaffold post title:varchar[50] body:text user_id:int --orm
    
    only creates the definition for the table structure, not the table structure itself. See if
    oil r migrate
    
    produces some better results. PS. As stated, this might not be relevant and I'm only new here. :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion