Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6709399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T07:52:37+00:00 2026-05-26T07:52:37+00:00

OK -this might be simple but i’m having trouble visualising where i need to

  • 0

OK -this might be simple but i’m having trouble visualising where i need to put what in ATK4.

I have a table (team) with columns id, name and reference. The id is an autoincrement colunm and a reference. In the table there are 3 rows like this

 id,  name,     last_ref
 1,  'Team 1',  1000
 2,  'Team 2',  1000
 3,  'Team 3',  2000

There is another table (story) with columns id, name, team_id and team_ref which after populating with data looks like this

 id, name, team_id, team_ref
  1, 'Story A', 1, 1001
  2, 'Story B', 1, 1002 
  3, 'Story C', 1, 1003
  4, 'Story D', 2, 1001
  5, 'Story E', 3, 2001

For each insert into the story table, the team_ref is looked up in the team table, incremented by 1 and the result stored against the story row. The last_ref field should also be updated immediately in case anyone else also inserts a new row into the story table.

So after the above inserts into the story table, the team table should look like below so each team is maintaining it’s own sequence and allocating the numbers in order.

 id,  name,     last_ref
 1,  'Team 1',  1003
 2,  'Team 2',  1001
 3,  'Team 3',  2001

The page where the story records are inserted is a CRUD but not sure if i should insert the logic into the CRUD, the page or the model itself. It should only impact inserts and i thought maybe it should be a defaultValue on the addField(‘last_ref’) but can i make this a function and where should the function be defined ?

A nice to have, although not essential, would be that incrementing of last_ref should skip any references that are already used in the table for the current team (in case inserted via some other means other than the CRUD).

Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T07:52:37+00:00Added an answer on May 26, 2026 at 7:52 am

    Certainly Model is the right place for database-related logic like this.

    Redefine beforeInsert function, which would lock tables, look up largest element and set the reference:

    function beforeInsert(&$data){
        $this->myLockTable();
        $next_ref = $this->myGetNextRef();
        $data['team_ref']=$next_ref;
        return parent::beforeInsert($data);
    }
    function afterInsert($id){
        parent::afterInsert($id);
        $team = $this->add('Model_Team')->loadData($this->get('team_id'));
        $team->set('last_ref',$this->get('team_ref'))->update();
        $this->myUnlockTable();
    }
    

    Functions here starting with “my” would be your custom-implemented ones.

    Then, assuming that you are using models properly, there would be no “other means” to insert record and you wouldn’t need to worry about skipping those entries.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a simple answer, but I am having some issues writing this
Alright, this might be simple but I dunno how to do it! I have
This might be very simple but I am new to MFC. I have a
this might be a simple question, but as I have zero experience in C++
This might be really simple but i have a service that returns a string
I know this might be a simple question but I have to make sure
This might be a pretty simple question but I'm a Crystal Reports newbie...I have
This might be simple but I'm starting out with rails. I have the following
This might seem like a simple question. But I have been looking for an
I thought this might be simple but i guess it's not, i have like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.