3

Do I always have to add new column in DB (by creating InstallSchema file) when I'm defining Extention Attribute (scalar) for an entity, or it's being done automatically somehow?

2

If you want to save Extension Attributes to DB than you need to add column.

Regarding DB : It stores to the relative table of entity.

For Example:

<extension_attributes for="Magento\SalesRule\Api\Data\RuleInterface">
    <attribute code="start_date" type="string" />
    <attribute code="end_date" type="string" />
    <attribute code="brands" type="string" />
</extension_attributes>

Above my code is for Sales Rule Extension Attributes, So it will store to RuleInterface realted table that is salesrule.

Hope Now its clear from you.

  • Thanks, it's a bit clearer now, yes. Do I have to set the column separately (in Install/Upgrade Schema)? – Pete Jaworski Apr 12 '18 at 9:28
  • Sure. If it clear your understanding, Mark up vote and accept answer to help others :) Happy Coding !! – Vivek Apr 12 '18 at 9:30
  • @PeteJaworski, Yes, You have to if you want to save it in DB. – Vivek Apr 12 '18 at 9:30
  • so if I want extension attribute for CartItemInterface then I might want to add column in quoteitem table, correct? – Pete Jaworski Apr 12 '18 at 9:42
  • @PeteJaworski, Yups, That Right. – Vivek Apr 12 '18 at 9:43
0

NO,you should define your attribute as an extension attribute by define your attribute in extension_attribute.xml at your module.

InstallSchema/UpgradeSchema does not able to define an attribute as extension attribute.

  • I know it should be defined in extension_attribute.xml, but where exactly is it stored in the DB? – Pete Jaworski Apr 12 '18 at 9:21
  • Yes, i have a attribute database like other attributes which are created from admin. Use of extension attribute is that to ability to update custom attribute via api . Actually, Now magento trying to use API class for frontend/admin. – Amit Bera Apr 12 '18 at 9:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.