Models and Auto Increment ID issue

Support MB Frontend Submission Models and Auto Increment ID issueResolved

Viewing 11 posts - 1 through 11 (of 11 total)
  • Author
    Posts
  • #47471
    Nicholas CoxNicholas Cox
    Participant

    Hi

    When I submit a form on the front end on a new custom table the first entry created takes the next post id and does not start from an ID of 1, why is this?

    $meta_boxes[] = [
    	'title'       => 'Test',
    	'model'       => 'example', 
    	'storage_type'=> 'test'
    	'table'       => 'wp_test',
    	'id'          => 'test',
    	'fields'      => [
    		[
    			'id'    => 'product_name',
    			'type'  => 'text',
    			'name'  => 'Product Name',
    		],
    	]
    ]
    MB_Custom_Table_API::create( 
    	"{$wpdb->prefix}" . 'test', 
    	[
    		'user_id' => 'BIGINT(20)',
    		'data' => 'TEXT NOT NULL', 
    		'iv' => 'VARCHAR(50)', 
    	],
    	['user_id'],
    	true // Must be true for models
    );
    #47472
    Nicholas CoxNicholas Cox
    Participant

    ignore the first code as this was just an example and not the correct code, but the issue still persists with the form code being correct to that of the table structure, i cannot edit my first post.

    #47484
    PeterPeter
    Moderator

    Hello Nick,

    It looks like the ID 1 was deleted in the database. I test to create the first entry of the custom model, the ID is started from 1 as well. But if I delete the entry in the database and submit a new entry, it will start from 2 as it is.
    I'm discussing this case with the development team and get back to you later.

    #47487
    Nicholas CoxNicholas Cox
    Participant

    Yes it seems it takes the next available wordpress post ID and not the next available ID of the custom model database table.

    #47501
    PeterPeter
    Moderator

    Hello Nick,

    I don't see it takes the default WordPress post ID instead of the custom model ID. However, if somehow the first custom model entry ID 1 was deleted, the ID will start from 2 and so on. The WordPress post ID also works like that.
    You can create a new post, delete it and create another post to see how the ID is generated.

    #47510
    Nicholas CoxNicholas Cox
    Participant

    Hi. Yes try adding a few default wordpress posts first and then try adding a row to the custom models database table. As I'm not sure if your test environment matches to replicate my issue? If not then no worries.

    What your describing is normal behaviour in regards to deleting the first databass table entry and adding a new entry which assigns an id of 2 etc... mysql tables behave like this with auto increment columns.

    My theory is that metabox is using some logic with posts which is causing the issue. As I have tested manually by inserting a new value and it works as intended with the first row having an id of 1.

    Any ideas? Thanks

    #47511
    Nicholas CoxNicholas Cox
    Participant

    So I have over 800 wordpress posts and when I insert the first row into a model table the ID is set to e.g. 806. Its weird behaviour not to be how metabox inserts new row values into custom model tables

    #47524
    PeterPeter
    Moderator

    Hello Nick,

    Can you please share a screen record that demonstrates the entry ID in the model table taking the next ID of WordPress post ID? Because I cannot reproduce that issue on my site.

    Thank you.

    #47575
    Nicholas CoxNicholas Cox
    Participant

    Hi,

    I will get a screen recording, but before i do I thought I read somewhere that I can use front end forms with custom models and custom tables now (but cannot find the information), as i posted this a few years ago https://support.metabox.io/topic/front-end-submission-and-custom-models/ which said that this was not supported. Can you confirm if custom models works with front end submission now? as i believe this is the reason why its not working.

    thanks

    #47576
    PeterPeter
    Moderator

    Hello Nick,

    The frontend submission form now supports submitting custom models from frontend. When using the frontend form shortcode, you should assign object_type to model.
    Please read more about this feature in the documentation
    https://docs.metabox.io/extensions/mb-frontend-submission/

    #47596
    Nicholas CoxNicholas Cox
    Participant

    Hi Peter,

    Ok that makes sense now, I have set the object_type to model and tested an all working ok now. Many thanks

Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.