Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORM Problems #1

Open
JeRoNZ opened this issue Jul 18, 2017 · 3 comments
Open

ORM Problems #1

JeRoNZ opened this issue Jul 18, 2017 · 3 comments
Labels

Comments

@JeRoNZ
Copy link

JeRoNZ commented Jul 18, 2017

I used this as an example (thanks) to build a shipping method. However, I found that repeated saves of the method through the dashboard lead to one record for each attempt.

The fix is to use the same ORM mechanism as used in the bundled community store methods, ie:

private function addOrUpdate($type, $data )
{
//////$em = Database::connection()->getEntityManager();
$em = \ORM::entityManager();
}
public function addMethodTypeMethod($data)
{
/////return $this->addOrUpdate('add', $data);
        return $this->addOrUpdate('update', $data);
}
@Mesuva
Copy link
Contributor

Mesuva commented Jul 18, 2017

Is this the same as what I was scratching my head on here?
concretecms-community-store/community_store#167

@JeRoNZ
Copy link
Author

JeRoNZ commented Jul 18, 2017

It sounds like exactly the issue I observed, yes. The two changes fixed it for me. I'm a bit of a noob at this ORM stuff, but it does seem to be the case that it's easy to detach or unmerge an object from ORM, such as might happen when creating a new instance of the entity manager, and that leads to a new record being inserted.

@JeRoNZ
Copy link
Author

JeRoNZ commented Jul 18, 2017

The code I ended up with is here:
https://github.com/JeRoNZ/community_store_shipping_nz_flat_rate

@Mesuva Mesuva added the bug label Sep 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants