Multiple Database Records with Same Primary KeyIterate through existing/newly saved objects or use addCommitCallback?Tables with non auto increment primary keyUpgrade to 1.9.2.2 - Base table or view already exists: 1050 Table 'mage_permission_variable' already existsproblem in installing fresh magento with same old databaseupdate the database query with ON DUPLICATE KEY UPDATEAdd to cart url returns invalid urlDetermine if item has own stock, i.e. is not a compound item and not virtualMagento Community form key from external site urlEditing Order instead of creating a new OrderRequested store not found

Why did C use the -> operator instead of reusing the . operator?

A faster way to compute the largest prime factor

How bug prioritization works in agile projects vs non agile

Why do distances seem to matter in the Foundation world?

Find the identical rows in a matrix

How long after the last departure shall the airport stay open for an emergency return?

Does a large simulator bay have standard public address announcements?

What to do with someone that cheated their way through university and a PhD program?

How do I produce this Greek letter koppa: Ϟ in pdfLaTeX?

Are there moral objections to a life motivated purely by money? How to sway a person from this lifestyle?

Multiple fireplaces in an apartment building?

Was Dennis Ritchie being too modest in this quote about C and Pascal?

SFDX - Create Objects with Custom Properties

My bank got bought out, am I now going to have to start filing tax returns in a different state?

Retract an already submitted recommendation letter (written for an undergrad student)

Which big number is bigger?

Prove that the countable union of countable sets is also countable

Is there metaphorical meaning of "aus der Haft entlassen"?

Can a stored procedure reference the database in which it is stored?

What is the unit of time_lock_delta in LND?

Why do games have consumables?

Creating a chemical industry from a medieval tech level without petroleum

How much of a wave function must reside inside event horizon for it to be consumed by the black hole?

Magical attacks and overcoming damage resistance



Multiple Database Records with Same Primary Key


Iterate through existing/newly saved objects or use addCommitCallback?Tables with non auto increment primary keyUpgrade to 1.9.2.2 - Base table or view already exists: 1050 Table 'mage_permission_variable' already existsproblem in installing fresh magento with same old databaseupdate the database query with ON DUPLICATE KEY UPDATEAdd to cart url returns invalid urlDetermine if item has own stock, i.e. is not a compound item and not virtualMagento Community form key from external site urlEditing Order instead of creating a new OrderRequested store not found






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I need to store relationships where a single attribute_id may be visible in multiple store_id and I was trying to use attribute_id as the primary key. It would be something like this:



+--------------+----------+
| attribute_id | store_id |
+--------------+----------+
| 147 | 1 |
| 147 | 2 |
+--------------+----------+


But Magento doesn't see that with good eyes as it returns the exception Item (foo) with the same ID "x" already exists.



What is the best solution for that problem?










share|improve this question






















  • I think you can't do that as Primary Key cannot be duplicated in any database.

    – magefms
    Apr 21 at 18:44






  • 1





    the best solution is to create new ID as primary key

    – magefms
    Apr 21 at 18:47











  • @magefms when I tried setting both of them as primary keys, the database accepted it, but not Magento... Anyway, I've thought about creating a new ID as primary key, but couldn't get a solution on how to update the relationship when it has too.. It is worth saying that I don't have much experience with databases management so if you know some technique or has some link to share on how to deal with this situation, I would be thankful. But thanks anyway

    – cslogic
    Apr 21 at 19:07

















1















I need to store relationships where a single attribute_id may be visible in multiple store_id and I was trying to use attribute_id as the primary key. It would be something like this:



+--------------+----------+
| attribute_id | store_id |
+--------------+----------+
| 147 | 1 |
| 147 | 2 |
+--------------+----------+


But Magento doesn't see that with good eyes as it returns the exception Item (foo) with the same ID "x" already exists.



What is the best solution for that problem?










share|improve this question






















  • I think you can't do that as Primary Key cannot be duplicated in any database.

    – magefms
    Apr 21 at 18:44






  • 1





    the best solution is to create new ID as primary key

    – magefms
    Apr 21 at 18:47











  • @magefms when I tried setting both of them as primary keys, the database accepted it, but not Magento... Anyway, I've thought about creating a new ID as primary key, but couldn't get a solution on how to update the relationship when it has too.. It is worth saying that I don't have much experience with databases management so if you know some technique or has some link to share on how to deal with this situation, I would be thankful. But thanks anyway

    – cslogic
    Apr 21 at 19:07













1












1








1








I need to store relationships where a single attribute_id may be visible in multiple store_id and I was trying to use attribute_id as the primary key. It would be something like this:



+--------------+----------+
| attribute_id | store_id |
+--------------+----------+
| 147 | 1 |
| 147 | 2 |
+--------------+----------+


But Magento doesn't see that with good eyes as it returns the exception Item (foo) with the same ID "x" already exists.



What is the best solution for that problem?










share|improve this question














I need to store relationships where a single attribute_id may be visible in multiple store_id and I was trying to use attribute_id as the primary key. It would be something like this:



+--------------+----------+
| attribute_id | store_id |
+--------------+----------+
| 147 | 1 |
| 147 | 2 |
+--------------+----------+


But Magento doesn't see that with good eyes as it returns the exception Item (foo) with the same ID "x" already exists.



What is the best solution for that problem?







magento-1.9 database






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 21 at 15:50









cslogiccslogic

1509




1509












  • I think you can't do that as Primary Key cannot be duplicated in any database.

    – magefms
    Apr 21 at 18:44






  • 1





    the best solution is to create new ID as primary key

    – magefms
    Apr 21 at 18:47











  • @magefms when I tried setting both of them as primary keys, the database accepted it, but not Magento... Anyway, I've thought about creating a new ID as primary key, but couldn't get a solution on how to update the relationship when it has too.. It is worth saying that I don't have much experience with databases management so if you know some technique or has some link to share on how to deal with this situation, I would be thankful. But thanks anyway

    – cslogic
    Apr 21 at 19:07

















  • I think you can't do that as Primary Key cannot be duplicated in any database.

    – magefms
    Apr 21 at 18:44






  • 1





    the best solution is to create new ID as primary key

    – magefms
    Apr 21 at 18:47











  • @magefms when I tried setting both of them as primary keys, the database accepted it, but not Magento... Anyway, I've thought about creating a new ID as primary key, but couldn't get a solution on how to update the relationship when it has too.. It is worth saying that I don't have much experience with databases management so if you know some technique or has some link to share on how to deal with this situation, I would be thankful. But thanks anyway

    – cslogic
    Apr 21 at 19:07
















I think you can't do that as Primary Key cannot be duplicated in any database.

– magefms
Apr 21 at 18:44





I think you can't do that as Primary Key cannot be duplicated in any database.

– magefms
Apr 21 at 18:44




1




1





the best solution is to create new ID as primary key

– magefms
Apr 21 at 18:47





the best solution is to create new ID as primary key

– magefms
Apr 21 at 18:47













@magefms when I tried setting both of them as primary keys, the database accepted it, but not Magento... Anyway, I've thought about creating a new ID as primary key, but couldn't get a solution on how to update the relationship when it has too.. It is worth saying that I don't have much experience with databases management so if you know some technique or has some link to share on how to deal with this situation, I would be thankful. But thanks anyway

– cslogic
Apr 21 at 19:07





@magefms when I tried setting both of them as primary keys, the database accepted it, but not Magento... Anyway, I've thought about creating a new ID as primary key, but couldn't get a solution on how to update the relationship when it has too.. It is worth saying that I don't have much experience with databases management so if you know some technique or has some link to share on how to deal with this situation, I would be thankful. But thanks anyway

– cslogic
Apr 21 at 19:07










1 Answer
1






active

oldest

votes


















1














Here is what I did, I created a relationship id column (like @magefms recommended) which happens to be the primary key, and whenever I need to update this relationship, I delete all the records that contains an specific attribute_id and create it again. To do that I implemented the following function in my model:



public function deleteByColumnValue($column, $value)

$collection = $this->getCollection()->addFieldToFilter($column, $value);
foreach($collection as $item)
$item->delete();




This function is probably available somewhere across Mage_Core, but I couldn't find it. Anyway, then on the controller save action, this is how I call it:



Mage::getModel('module/model')->deleteByColumnValue('attribute_id', $storeId);


Hope this is helps someone!






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270887%2fmultiple-database-records-with-same-primary-key%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Here is what I did, I created a relationship id column (like @magefms recommended) which happens to be the primary key, and whenever I need to update this relationship, I delete all the records that contains an specific attribute_id and create it again. To do that I implemented the following function in my model:



    public function deleteByColumnValue($column, $value)

    $collection = $this->getCollection()->addFieldToFilter($column, $value);
    foreach($collection as $item)
    $item->delete();




    This function is probably available somewhere across Mage_Core, but I couldn't find it. Anyway, then on the controller save action, this is how I call it:



    Mage::getModel('module/model')->deleteByColumnValue('attribute_id', $storeId);


    Hope this is helps someone!






    share|improve this answer



























      1














      Here is what I did, I created a relationship id column (like @magefms recommended) which happens to be the primary key, and whenever I need to update this relationship, I delete all the records that contains an specific attribute_id and create it again. To do that I implemented the following function in my model:



      public function deleteByColumnValue($column, $value)

      $collection = $this->getCollection()->addFieldToFilter($column, $value);
      foreach($collection as $item)
      $item->delete();




      This function is probably available somewhere across Mage_Core, but I couldn't find it. Anyway, then on the controller save action, this is how I call it:



      Mage::getModel('module/model')->deleteByColumnValue('attribute_id', $storeId);


      Hope this is helps someone!






      share|improve this answer

























        1












        1








        1







        Here is what I did, I created a relationship id column (like @magefms recommended) which happens to be the primary key, and whenever I need to update this relationship, I delete all the records that contains an specific attribute_id and create it again. To do that I implemented the following function in my model:



        public function deleteByColumnValue($column, $value)

        $collection = $this->getCollection()->addFieldToFilter($column, $value);
        foreach($collection as $item)
        $item->delete();




        This function is probably available somewhere across Mage_Core, but I couldn't find it. Anyway, then on the controller save action, this is how I call it:



        Mage::getModel('module/model')->deleteByColumnValue('attribute_id', $storeId);


        Hope this is helps someone!






        share|improve this answer













        Here is what I did, I created a relationship id column (like @magefms recommended) which happens to be the primary key, and whenever I need to update this relationship, I delete all the records that contains an specific attribute_id and create it again. To do that I implemented the following function in my model:



        public function deleteByColumnValue($column, $value)

        $collection = $this->getCollection()->addFieldToFilter($column, $value);
        foreach($collection as $item)
        $item->delete();




        This function is probably available somewhere across Mage_Core, but I couldn't find it. Anyway, then on the controller save action, this is how I call it:



        Mage::getModel('module/model')->deleteByColumnValue('attribute_id', $storeId);


        Hope this is helps someone!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 21 at 20:08









        cslogiccslogic

        1509




        1509



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f270887%2fmultiple-database-records-with-same-primary-key%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sum ergo cogito? 1 nng

            419 nièngy_Soadمي 19bal1.5o_g

            Queiggey Chernihivv 9NnOo i Zw X QqKk LpB