[code]
class Model_Fanuser extends \Orm\Model
{
protected static $_properties = array(
'id',
'first_name',
...
'created_at',
'updated_at',
);
protected static $_many_many = array(
'teams' => array(
'key_from' => 'id',
'key_through_from' => 'fanuser_id', // column 1 from the table in between, should match a posts.id
'table_through' => 'fanusers_teams', // both models plural without prefix in alphabetical order
'key_through_to' => 'team_id', // column 2 from the table in between, should match a users.id
'model_to' => 'Model_Team',
'key_to' => 'id',
'cascade_save' => false,
'cascade_delete' => false,
),
'stickers' => array(
'key_from' => 'id',
'key_through_from' => 'fanuser_id', // column 1 from the table in between, should match a posts.id
'table_through' => 'fanusers_stickers', // both models plural without prefix in alphabetical order
'key_through_to' => 'sticker_id', // column 2 from the table in between, should match a users.id
'model_to' => 'Model_Sticker',
'key_to' => 'id',
'cascade_save' => false,
'cascade_delete' => false,
)
);
protected static $_observers = array(
'Orm\Observer_CreatedAt' => array(
'events' => array('before_insert'),
'mysql_timestamp' => false,
),
'Orm\Observer_UpdatedAt' => array(
'events' => array('before_save'),
'mysql_timestamp' => false,
),
);
[code]
and I have this function :[code]
public function addSticker($sticker_id, $mode='one')
{
$hasIt = 0;
if( is_array($this->stickers) )
{
foreach( $this->stickers as $k => $sticker )
{
if( $sticker->id == $sticker_id )
{
$hasIt++;
}
}
}
// is a one-only-sticker
if( $mode=="one" && $hasIt>0 )
{
// no sticker. he already have the sticker
}
else
{
$this->stickers[] = Model_Sticker::find($sticker_id);
return $this->save(false);
}
}
[code]
the problem is, that when I give a sticker to a user, everything goes well in the DB, but the created_at and updated_at fields ARE NOT FILLED with the timestamp.'created_at' => array('type' => 'timestamp', 'default' => \DB::expr('CURRENT_TIMESTAMP')),
\DB::query(<<<EOS
CREATE TABLE IF NOT EXISTS `cms_blocks` (
`id` int UNSIGNED NOT NULL AUTO_INCREMENT,
`uniqid` varchar(125) NOT NULL,
`content` text NOT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NOT NULL ON UPDATE CURRENT_TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
UNIQUE `page_uniqid` (uniqid)
) ENGINE=`InnoDB` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
EOS
)->execute();Now only this code works fine for me...
It looks like you're new here. If you want to get involved, click one of these buttons!