I need to have profile field creation date (saved as a column in database table). How would You solve this problem? I've tried a few things, but solutions intended to work on pure sql level (triggers, default values) somehow don't work combined with backdrop.

Almost as if user entity was dropped and inserted on every save.

Comments

Things are getting messy. Only way I've found to set creation date is by making use of entity presave and update hooks. Basically I'm checking for new fields in entity 'profile' before and after save (see code). For some reason update doesn't work, though select returns fields on which I want to perform an update. SIGH.

function my_entity_presave($entity, $type){
    
    $codeDiscount = UserInfo::getCodeDiscount(false);
    variable_set('arr_code_discount', $codeDiscount);
    
}

function my_entity_update($entity, $type) {
    
    $codeDiscount = UserInfo::getCodeDiscount(false);
    $prevCodeDiscount = variable_get('arr_code_discount');

    $arr_prev = array();
    $arr_current = array();
    
    foreach($prevCodeDiscount as $k){
        $arr_prev[] = $k->field_bonus_value;
    }
    foreach($codeDiscount as $k){
        $arr_current[] = $k->field_bonus_value;
    }
    
    $arr_diff = array_diff($arr_current, $arr_prev);
    
    if($arr_diff && count($arr_current) >= count($arr_prev) && $entity->type == 'uczestnik'){
        foreach($arr_diff as $k){
            
            $sql = "
              SELECT * FROM field_data_field_bonus WHERE field_data_field_bonus.entity_id = " . $entity->pid;
              dpm($sql);            
            $args = array();
            $res = db_query($sql, $args);
            dpm($res->fetchAll());//it's ok - freshly added fields are visible            

            db_update('field_data_field_bonus')
            ->fields(array(
              'created' => 'testval',
            ))
            ->condition('entity_id', $entity->pid)
            ->condition('field_bonus_value', $k)
            ->execute();//this doesn't work from here, but works ok from within mysql workbench...

        }
    }
    
}

Ok, it looks like my efforts are in vain, since probably all user profile fields are written to the cache and then inserted again as 'revision' or something like this...

Does anyone have any idea how to implement this kind of functionality in backdrop cms? ('created' column, not only 'changed')

I'm not understanding what youre trying here sorry.

Ok, it goes like this:

Standard install, default user profile - number of fields is limited to email, password, etc.

I need different user profiles (say: spectator, runner, journalist), so I use 'profile' module (which in drupal 7 was called 'profile2'). This way I can have registration form with a few dozen inputs to fill out and different registration addresses for different folks (module 'profile_reg_path').

Alll is fine and dandy, but every now and then I get the request from a client along the lines of 'get me a list of users, which have chosen some option from the user form after some date'. For example 'I want a party'. And I need to know, when did someone exactly created field 'field_data_field_party'. 

So, in addition to the 'changed' column, I would like to have 'created' column in database table 'field_data_field_party' and all the other tables would be nice too.

I know this works for nodes, but I need finer granularity, so to speak...

Seen. Fields dont have created dates it seems. So no way to know when a user changed a particular field in their profile.

There is a way to know last modification date, but not creation date. I'm trying to find some kind of database schema right now...

Couldn't solve it the way I thought would be best and elegant.

Resolution lies somewhere in field_sql_storage module, probably, though functions there are "fallback for pre-operation hooks" of field module, and I was too short to dissect all this, not to mention time running out.

So on a third day of my work I just created a table "coupon_creation_dates" slapped a few columns on it and never looked back...