2

If I'd like to have a table with three columns:

  • firstname,
  • lastname and
  • username (a combination of firstname and lastname)

I'd like the table to auto generate the username as soon as a record is inserted with a first & lastname.

Please note that I would like it to do so in an automated fashion, without the use of a cronjob or something as such.

How can I set this up efficiently? From what I understand MySQL does not support declarative computed fields.

According to this page: MySQL 5.0 Reference Manual :: 18 Stored Programs and Views :: 18.3 Using Triggers

  • MySQL triggers activate only for changes made to tables by SQL statements. They do not activate for changes in tables made by APIs that do not transmit SQL statements to the MySQL Server; in particular, they are not activated by updates made using the NDB API

I am using version 5.0.95 which should support triggers. Do you think Magento's ORM will be compatible with this?

2
  • 2
    Could you please explain why do you need this because, I don't understand the purpose of your third field. As combining first two you can always get third one. Commented Feb 19, 2014 at 7:22
  • I'd prefer not to implement additional logic throughout an existing system covering a very large database, this scaled down version of the scenario accurately describes the requirements.
    – Moose
    Commented Feb 19, 2014 at 7:29

1 Answer 1

1

Since EE 1.13 and CE 1.8 Magento uses SQL triggers itself for real-time indexing. So they already work with the Magento ORM.

According to this page: MySQL 5.0 Reference Manual :: 18 Stored Programs and Views :: 18.3 Using Triggers

  • MySQL triggers activate only for changes made to tables by SQL statements. They do not activate for changes in tables made by APIs that do not transmit SQL statements to the MySQL Server; in particular, they are not activated by updates made using the NDB API

I am using version 5.0.95 which should support triggers. Do you think Magento's ORM will be compatible with this?

Creating your own triggers works well independent of the Magento version. Magento's ORM only makes changes with normal SQL statements so the quoted issue does not apply.

1
  • does 1.7.x and below support SQL triggers?
    – Moose
    Commented Feb 19, 2014 at 8:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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