That works great to add a new database and add attributes to it, but I want to add attributes to an existing database
I tried grabbing the database object with
$object = Express::getObjectByHandle(‘marina’);
But that shows an error, Call to undefined method Concrete\Core\Entity\Express\Entity::addAttribute() Does anyone have an example on how to do this? Thanks
I think you cannot do it using current Concrete api. At least I haven’t found any class that can do it.
If someone knows better, I will be happy to be proved wrong:D
Express::buildObject() will create instance of Concrete\Core\Express\ObjectBuilder
where addAttribute() method is available.
Though save() method will return Concrete\Core\Entity\Express\Entity instance.
Express::getObjectByHandle(‘marina’) will return Concrete\Core\Entity\Express\Entity
so addAttribute() method is not available.
Going back to Concrete\Core\Express\ObjectBuilder class, it seems it can only build express objects from zero. There isn’t any setObject()/setEntity() method or something like that.
I was able to add attribute to existing Express object, but only by operating on entity manager directly (blatantly say by “stealing” code from core files). Though I don’t have that much experience with Express so I don’t know if it was ingenious or sketchy.
Just came back from the docs. Seems like it is not there and the paste i sent in the previous reply relies on this extension:
namespace Concrete\Package\YourPackage;
use Concrete\Core\Express\ObjectBuilder as CoreObjectBuilder;
class ObjectBuilder extends CoreObjectBuilder
{
public function setEntity($entity)
{
$this->entity = $entity;
}
}
Hi all. I came across this post as it is exactly what I needed. But unfortunately, I am getting an error I can’t solve.
Object { type: “Doctrine\ORM\Exception\EntityMissingAssignedId”, message: “Entity of type Concrete\Core\Entity\Attribute\Key\Settings\TextSettings is missing an assigned ID for field ‘key’. The identifier generation strategy for this entity requires the ID field to be populated before EntityManager#persist() is called. If you want automatically generated identifiers instead you need to adjust the metadata mapping accordingly.”, code: 0, … }