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 8001417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T16:05:21+00:00 2026-06-04T16:05:21+00:00

I am developing a custom Magento module that needs to save a list of

  • 0

I am developing a custom Magento module that needs to save a list of email addresses into a custom table. The relevant code looks like this:

foreach($this->getNewSubscriptionsForAPI() as $email){
            $requestModel->setEmail($email);
            $requestModel->setAction('subscribe');
            $requestModel->setPosted(date('Y-m-d H:i:s'));
            $requestModel->save();
        }

The getNewSubscriptionsForAPI() method is returning valid data, and the $requestModel is a valid Magento model.

When this loop runs, however, the database adaptor simple overwrites each record on top of the previous one. Ie, if I repeatedly hit ‘browse’ in phpMyAdmin I can see different email addresses being written to the database but always in the same row, overwriting the previous entry. The id field is correctly set up: as primary key, set to AUTO_INCREMENT, and flagged as the id field in the resource model.

What’s interesting is that I can use the loop above to write successive records in the core newsletter/subscriber table with no problem.

I could, of course, simply unset() the model and get it back out of the Mage::getModel() at each cycle of the loop, but this (a) seems hugely wasteful, and (b) spoils my Dependency Injection setup for testing (where I don’t want the code to be instantiating its own models, but using the ones I pass to it).

Can anyone point me in the right direction?

  • 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-06-04T16:05:22+00:00Added an answer on June 4, 2026 at 4:05 pm

    When Magento saves a new object it automatically generates an id for the object. After you have saved the object hence an id is generated. To make magento recognize your data as a new model again, you simply need to unset the model id. I think however unsetData is more elegant as it also erases any data that might have been created for the previous object :-).

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

Sidebar

Related Questions

I am developing a custom control that needs it's viewstate to be loaded on
I'm currently developing a custom control and realize that my code is being run
We are developing a custom textual DSL, that will ultimately get integrated into Visual
I am developing custom list field using Table Row Manager in blackberry.it displays list
I'm developing a Custom Action to install the same file into multiple folders(that are
I'm developing a custom module for Drupal 6, that creates a simple form. My
I'm developing a custom module for my Magento installation (version 1.6.2.0). I registered a
I'm currently developing a custom control that derives from CStatic MFC class (Smart Device
I am currently developing a custom WordPress theme and ran into a problem. I
Say you're developing a custom control and there's a key template part that your

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.