Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Is Not Model_Soft "deleted_at" Setted Automatically by ORM sql builder?
  • Hello.
    I wont to Select Joined 2 Tables by ORM.

    There are 2 tables "Users" and "Reports".
    "Users" has many "Reports" records.
    "Reports" table has "user_id" that's foreign key.

    --------------------------------------------------------------------
    /* Model_*/
    --------------------------------------------------------------------
    class Model_User extends \Orm\Model_Soft{

    protected static $_has_many =
        array(
            'report' => array(
                'model_to' => '\Service\Model_Report',
                'key_from' => 'id',
                'key_to' => 'user_id',
            )
        );

    protected static $_soft_delete =
        array(
            'deleted_field' => 'delete_time',
            'mysql_timestamp' => true,
        ); 

    --------------------------------------------------------------------
    /* Controller (In Modules) */
    --------------------------------------------------------------------
    $test = \User\Model_User::query()
                ->related('report')
                ->get();

    --------------------------------------------------------------------
    /* SQL */
    --------------------------------------------------------------------
    SELECT `tbl_t0`.`id` AS `t0_c0`....
    LEFT JOIN `tbl_reports` AS `tbl_t1`
    ON (`tbl_t0`.`id` = `tbl_t1`.`user_id` AND `tbl_t1`.`delete_time` IS NULL)

    ###########################################

    I wont to set 'tbl_t1' delete_time.
    Isn't It setted automatically?
     
  • Where should it set that? It won't do that until you delete something.

    Your running a get() in your controller, which produces that SELECT statement. In other words, it only selects records that were not deleted.
  • Sorry, mistake...
    > I wont to set 'tbl_t1' delete_time.
    It's wrong.

    >I wont to set 'tbl_t0' delete_time.
    It's correct.

  • I dont see an $object->delete() in your code, so where exactly should it set the delete time on that table?
  • My English is duty, sorry.
    I wont SELECT, not UPDATE.

    I wont to do:
    --------------------------------------------------------------------
    /* SQL */
    --------------------------------------------------------------------
    SELECT `tbl_t0`.`id` AS `t0_c0`....
    LEFT JOIN `tbl_reports` AS `tbl_t1`
    ON (`tbl_t0`.`id` = `tbl_t1`.`user_id` AND `tbl_t0`.`delete_time` IS NULL AND `tbl_t1`.`delete_time` IS NULL )

    but, now damped SQL is:
    --------------------------------------------------------------------
    /* SQL */
    --------------------------------------------------------------------
    SELECT `tbl_t0`.`id` AS `t0_c0`....
    LEFT JOIN `tbl_reports` AS `tbl_t1`
    ON (`tbl_t0`.`id` = `tbl_t1`.`user_id` AND `tbl_t1`.`delete_time` IS NULL )




  • HarroHarro
    Accepted Answer
    Ah, ok, now I understand.

    Please make sure you run the latest version (1.6.1), and if it is still an issue, please file a bug report at https://github.com/fuel/orm/issues so it can be looked at.
  • OK, Now I Posted.
    Waiting For Fix :)
    Thank You!

Howdy, Stranger!

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

In this Discussion