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

DbId expected, not expected, present but not recognised #9

Open
flokstra81 opened this issue Nov 22, 2022 · 3 comments
Open

DbId expected, not expected, present but not recognised #9

flokstra81 opened this issue Nov 22, 2022 · 3 comments

Comments

@flokstra81
Copy link

With executing the insert query i got a lot further! Many thanks for that.

Now i've got an od problem when updating. When executing an update query for a KnSalesRelationPer, I am using a valid DbId and receive the following error:

Fatal error: Uncaught Afas\Core\Exception\EntityValidationException: Attribute DbId is not set for KnSalesRelationPer. Unknown property 'DbId' in 'KnSalesRelationPer'.

So part one says it can't find DbId and part two says it doesn't know what to do with DbId... It is set and valid. I've doublechecked many times.

What to do next?

@MegaChriz
Copy link
Owner

You need to specify which fields need to be set as attributes, so like this:

$data = [
  'DbId' => 12345,
];
$attributes = ['DbId'];
$server->update('KnSalesRelationPer', $data, $attributes)
  ->execute();

This will result in XML like the following:

<KnSalesRelationPer xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <Element DbId="12345">
    <Fields Action="update">
    </Fields>
  </Element>
</KnSalesRelationPer>

I see that an example doing something like the above is also missing. Looks like I should revisit the example code and add some more useful ones. 🫣 I think I added the examples at a time that the library wasn't yet completed. I remember that I started with some examples to get an idea how I wanted the library to work. And apparently I didn't update them when the library became more mature.

Also, I guess it would be a nice to have if the library is smart to know which of the fields it should use as an attribute.

@flokstra81
Copy link
Author

Perfect! Thanks for the fast reaction. And yes it would be a great asset for the library to automatically determine the attributes from the given data. Also shouldn't be too complicated I think.

Am I right in understanding I only have to specify the attributes when updating? While inserting worked perfectly without specifying them.

@MegaChriz
Copy link
Owner

Attributes aren't always required indeed. When inserting a new relation there is no customer ID available yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants