Giter Site home page Giter Site logo

thecodingmachine / tdbm Goto Github PK

View Code? Open in Web Editor NEW
118.0 9.0 27.0 5.33 MB

The Database Machine is a PHP ORM that requires no configuration. The object model is deduced from the database model.

Home Page: https://thecodingmachine.github.io/tdbm/

PHP 99.45% Shell 0.38% Dockerfile 0.17%

tdbm's Introduction

tdbm's People

Contributors

brain-diminished avatar camillekoppel avatar cbalda avatar charlesc-tcm avatar dependabot-preview[bot] avatar dependabot[bot] avatar dsavina avatar fooriva avatar gulien avatar harikt avatar homersimpsons avatar jdreesen avatar kharhamel avatar lebacql avatar mhtghn avatar mirsch avatar moufmouf avatar nguyenk avatar nipatcm avatar npeguin avatar quentindubes avatar theobiron avatar thibbal avatar vaidiep avatar xhuberty avatar zheness avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tdbm's Issues

Fix second params of findOneBy in file Abstract

When I generate DAOs, in files like Abstract (no editable), DAO can generate function findOneBy .. like this for example in AbstractDocumentTypeDao :

    /**
     * Get a DocumentType filtered by whiteLabel, documentModels.
     *
     * @param WhiteLabel $whiteLabel
     * @param DocumentModel $documentModels
     * @param string[] $additionalTablesFetch A list of additional tables to fetch (for performance improvement)
     * @return DocumentType|null
     */
    public function findOneByWhiteLabelAndDocumentModels(WhiteLabel $whiteLabel, ?DocumentModel $documentModels = null, array $additionalTablesFetch = array()) : ?DocumentType
    {
        $filter = [
            'white_label_id' => $whiteLabel->getId(),
            'document_models_id' => ($documentModels !== null) ? $documentModels->getId() : null,
        ];
        return $this->findOne($filter, [], $additionalTablesFetch);
    }

In my schema DB, white_label_id and document_models_id are NOT NULL

So, second params should not be an optional parameter.

Can it be corrected? Thank you

Syntax error when generating Bean for columns starting with a number

Process: I've added a column "4d_external_id" using a migration. Then I've generated the DAO/Beans using tdbm:generate command. No error from the command.

But the new generate Abstract file has now a syntax error because of a new getter/setter

set4dExternalId(?int $4d_external_data): Unexpected integer.

Potential fix: when generating the files, if the column start with an integer, add an underscore (_) before the name of the variable.

findFromRawSql() doesn't accept DISTINCT

Hello,

I'm trying to use findFromRawSql with a custom query and instead of having SELECT table.* FROM as the doc:

You should not put an alias on the main table name, and select its columns using `*`. So the SELECT part of you $sql should look like:

    "SELECT table.* FROM ..."

I'm using SELECT DISTINCT table.* FROM but I got an error:

Exception:
Invalid array. Could not find expression type: array (
  'delim' => ',',
)

LINE: 23
FUNCTION: SQLParser\Node\NodeFactory::toObject()
FILE: /var/www/html/vendor/mouf/magic-query/src/SQLParser/Node/NodeFactory.php 

Is the usage of DISTINCT not possible ? If so, maybe change the doc from should look like to must look like ?

Thanks

Error when having a many to many relationships table between the same entity

My model:

  • I have a geo_locations table which is composed by locations (cities, regions, countries, departments)
  • I have a table named geo_locations_relations, a many to many relationships table that is used to describe the relation between a location and one of its parents :
    ex: Paris 8e Arrondissement -> Paris
    ex2: Paris -> Ile de France
    ex3 : Paris 8e Arrondissement -> Ile de France

Structure of the geo_locations_relations table:

  • id PK
  • parent_location_id FK geo_locations
  • location_id FK geo_locations

Behaviour:

  • TDBM5 doesn't create the DAO of the table (that's normal) but generate a function in the AbstractGeoLocation Bean named getGeoLocationsByGeoLocationsRelations
  • But this function doesn't work. When executed, an error occurred:
    "There are many possible shortest paths between table 'geo_locations' and table 'geo_locations_relations'
    Path 1: geo_locations <--(location_id)-- geo_locations_relations
    Path 2: geo_locations <--(parent_location_id)-- geo_locations_relations"

What I would like: I don't know 🙃 Maybe two functions which specify the column to use for the path (the starting point):

  • getGeoLocationsByGeoLocationsRelationsUsingLocationId
  • getGeoLocationsByGeoLocationsRelationsUsingParentLocationId

Cannot save new Bean with a relationship not on primary key

Hello,

I have a table event with 2 columns:

  • idevent the primary key
  • nid an int column

And my second table preference with 2 columns:

  • idpreference the primary key
  • event_nid an indexed column with a relationship on event.nid

When I try to save a new PreferenceBean, I must pass an EventBean, but on save(), it's event.idevent which is took instead of event.nid according to the relationship.

Thanks

Cloning table with UUID primary key

When cloning a table with a UUID primary key, the cloned object does not have a new UUID generated. Instead, the primary key is empty.

We should expect a new UUID to be generated instead.

Cannot find objects on unique index with nullable column

Let's say I have a table with 2 foreign keys. Both keys are part of the same unique index.

TDBM generates the following function :

findOneByAandB(A $a, ?B $b = null){
        $filter = [
            'a_id' => $a->getId(),
            'b_id' => ($b !== null) ? $b->getId() : null,
        ];
        return $this->findOne($filter, [], $additionalTablesFetch);
}

Question 1 : why is the second argument nullable and optional ?

Question 2 : If the first FK is nullable, I should be able to query the same function by passing null for the nullable column :

$result = $dao->findOneByAandB(null, $b);

...but this is not possible given the actual signature first input cannot be null, and even if we change the signature, this will still not work because the filter is not asking for explicit null value. It will, in fact query b_id = [ID_OF_B] only.

DaoFactory performance issues with Mouf framework (5.0.16)

Hello !

I was told that injecting DaoFactory is somehow deprecated because it causes performance issues (when injecting, all DAOs are loaded or someting) !
I don't know it it's related to Mouf or TDBM, but its a shame ! DaoFactory is really convenient and it would be really nice to keep using it, since its generated !

Thanks

Wrap "save" into a transaction

We need to wrap save into a transaction to be sure to not save a bean partially (for instance saving the main bean but failing to save the many to many relationships)

Improvement? Throw error when key parameter not found

Hello !

I would like to know if it's possible to throw an error to indicates that a key has not been found in the parameter list ?

For example:

return $this->find('foo = :foo AND bar = :bar AND baz = :baz', [
    'foo' => 42,
    'baar' => 'Wrong key',
    'baz' => null
]);

In my code, I expect a key bar that is not provided, and would like to throw an error because my query will be wrongly executed if i mistype a parameter key.

I understand that when a value is null, it should work properly by removing the condition internally. But I expect that for not found key, it should not behave like that.

Is there any way to avoid the query to be executed if a key is missing ?

Thank you !

Nested iteration problem

On a many-to-one relationship, if there are two nested foreach, the first foreach does not complete successfully.

Example :

$activities = $entity->getActivities();
foreach($activities as $activity){
    foreach($activities as $activity2){
        // BOOM ! Nested iteration issue
    }
}

Manual installation guide issues

I've recently come across this library and I'd like to make use of it in my project that uses no frameworks, but unfortunately I seem to have hit a roadblock right off the bat.

I'm trying to follow the following installation guide: https://thecodingmachine.github.io/tdbm/doc/manual_install.html

The first thing that was immediately obvious upon opening the doc compared to the other ones is that it does not mention what package to even install from Composer, I had to find this repository and get the package name from the Composer JSON.

Then follows the real kicker, taking the code from that page, my IDE immediately complained that I passed no arguments to new TheCodingMachine\TDBM\Utils\DefaultNamingStrategy(). Rightfully so, as running the code without it also throws.

PHP Fatal error: Uncaught ArgumentCountError: Too few arguments to function TheCodingMachine\TDBM\Utils\DefaultNamingStrategy::__construct(), 0 passed in file.php on line 22 and exactly 2 expected in .../vendor/thecodingmachine/tdbm/src/Utils/DefaultNamingStrategy.php:40

I found this confusing and I'm not really sure how to move forward.

OneToOne inverse relation is Mapped as OneToMany

SQL Schema:

CREATE TABLE `object` (
  `id` INT NOT NULL,
  PRIMARY KEY (`id`));
CREATE TABLE `media` (
  `id` INT NOT NULL,
  `object_id` INT NOT NULL,
  PRIMARY KEY (`id`),
  FOREIGN KEY fk_object(object_id)
   REFERENCES object(id));

TDBM generate a getter on the Object Entity named getMediasByObjectId(): AlterableResultIterator.

Here, because of the unique index on object_id, the relation is a OneToOne and not a OneToMany, so the generated method should have been getMediaByObjectId(): ?Media (notice the return type is nullable as TDBM can't ensure the existence)

Idea : in jsonSerialize() when $stopReccursion equals true, include the key of the ignored object

Present : When the jsonSerialize() method is called, is the $stopReccursion equals true, the referenced entities are not serialized in the returned data and no key is included to replace the ignore object.

What I would like : In the same situation, include the value of the foreign key column.

Ex:

  • When $stopReccursion === false :
    {id: 123, label: "TheCodingMachine", type: {id: 1, label: "Company"}}

  • When $stopReccursion === true :
    {id: 123, label: "TheCodingMachine", typeId: 1}

Idea: use custom result iterators per tables to provide on-the-fly filtering

We could generate custom iterators per table that can be customized by users to offer "on the fly filtering".

It could work like this:

$users = $userDao->findAll()->filterActiveUsers()->filterAdults();

Behind the scene, the findAll() method returns a UserResultIterator (instead of a simple ResultIterator). The UserResultIterator has been coded by the developer (I'm not sure exactly how yet...)

Maybe something like:

class UserResultIterator extends ResultIterator {
    public function filterActiveUsers() : ResultIterator {
        return $this->andSqlFilter('active = 1');
    }
}

You think this is a good idea?

Compatibility with Doctrine's MemcachedCache

It looks like the keys generated by FindObjectsQueryFactory in the compute() method (for example) contain spaces in the filterString and therefore the cache $key, which Doctrine's MemcachedCache class does not allow:

https://github.com/doctrine/cache/blob/master/lib/Doctrine/Common/Cache/MemcachedCache.php

See the validateCacheId() method.

Sidenote: I am triggering this problem by performing a $this->find() method call within a Dao object, such as:
return $this->find("user_agent IN (:user_agent)", [ 'user_agent' => implode(',', $user_agent) ]);

In this example, this part of the query ends up in the filterString ("user_agent IN (:user_agent)") and that is where the spaces are.

When tested with ArrayCache or ApcuCache it works fine.

DAO generated getter by unique index fails depending on column order

Context :

Table A
id : pk
label
Table B
id : pk
name
a_id

b.a_id points to a.id

*SQL : *

CREATE TABLE `a` (
  `id` int(11) NOT NULL,
  `label` varchar(10) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Contenu de la table `a`
--

INSERT INTO `a` (`id`, `label`) VALUES
(1, 'foo');

-- --------------------------------------------------------

--
-- Structure de la table `b`
--

CREATE TABLE `b` (
  `id` int(11) NOT NULL,
  `name` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `a_id` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

--
-- Contenu de la table `b`
--

INSERT INTO `b` (`id`, `name`, `a_id`) VALUES
(1, 'bar', 1);

--
-- Index pour les tables exportées
--

--
-- Index pour la table `a`
--
ALTER TABLE `a`
  ADD PRIMARY KEY (`id`);

--
-- Index pour la table `b`
--
ALTER TABLE `b`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `uniquetest` (`name`,`a_id`),
  ADD KEY `a_id` (`a_id`);

--
-- AUTO_INCREMENT pour les tables exportées
--

--
-- AUTO_INCREMENT pour la table `a`
--
ALTER TABLE `a`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
--
-- AUTO_INCREMENT pour la table `b`
--
ALTER TABLE `b`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

ALTER TABLE `b`
  ADD CONSTRAINT `b_ibfk_1` FOREIGN KEY (`a_id`) REFERENCES `a` (`id`);

See in script, index uniquetest has order name, then a_id.

Generate DAOs, then call :
$b = $bDao->findOneByNameAndA("bar", $a);
==> returns a B instance

Now hold tight !! Inverse index order :

ALTER TABLE b DROP INDEX uniquetest
ALTER TABLE `tdbmtest`.`b` ADD UNIQUE `uniquetest` (`a_id`, `name`);

Regenerate DAOs, then call :
$b = $bDao->findOneByAAndName($a, "bar");
==> returns wait for it.... NULL :'(

There is no way to return an empty result iterator in a DAO

See code below:

    public function findSomething(PurchasingGroup $purchasingGroup)
    {
        if ($purchasingGroup->getIdcompany() === null) {
            return [];
        }
        return $this->find(
            'companies.parent_company_id = :idparent AND companies.status = :status',
            [
                'idparent' => $purchasingGroup->getIdcompany(),
                'status' => 'on'
            ]
        );
    }

The return []; part is problematic because it makes the return type "array|ResultIterator".
We should have a way to return an empty result iterator.

Ideally:

return ResultIterator::getEmptyResultIterator();

Improve error logging with DuplicateRowExecption

Hello,

Is it possible to improve error message when DuplicateRowException occurs ?

Currently we have something like "More than 1 row have been returned, but we should have received at most one", but we don't have any hint about what field and value.

Thank you :)

Mass update a lot of items

Hi,

I am looking for a way to update all of my lines in one specific table (switch a boolean on each line). How can I do that without using a loop in PHP which will result, if I am not mistaken, in one SQL request for each line ?

I'd like to have a way to execute a raw SQL request or any other way of updating all of my items at once. Is this possible ? I can't find anything about this in the documentation.

Thanks

Error when sorting on a column of a child table.

An error occurs when sorting on a column from a children table and fetching beans from the parent table.

For instance (in the test dataset): performing a "find" on the "PersonDao" while sorting on "users.email"

Generation error with a table without primary key

Hello,

When I try to generate the DAOs with a table without a primary key, the generation stops with an unclear message:

Error: Call to a member function getUnquotedColumns() on null in /var/www/html/vendor/thecodingmachine/tdbm/src/Utils/TDBMDaoGenerator.php on line 210

Thanks

Idea: filter by result iterator

We could filter a query by result iterators.
Since the result iterator contains a link to the query factory, we could use the query factory to write the part of the subquery needed.

for instance:

$results = $userDao->find("status = 'deleted'")

could translate to:

SELECT id FROM users WHERE status = 'deleted'

(basically, it is the same thing as the full query but only with ids as columns)

We can then put this query into another query:

$countriesWithDeletedUsers = $coutryDao->find($results);

which will generate:

SELECT * FROM MAGICQUERY(countries) WHERE countries.id IN (SELECT id FROM users WHERE status = 'deleted')

It is not the most efficient way to write the query, but it shall do the trick.

Alternative syntax:

$countriesWithDeletedUsers = $coutryDao->find('countries.id IN : countries', 
    ['countries' => $results]);

Add support for views (?)

TDBM does nothing with views.

We could consider building DAOs and immutable beans when a view is encountered.

If you are interested with this feature, plus send a +:1+ on this issue.

Add support for Blob and binary types

When I create a table with blob type, I cannot call getter on this property because expected return type is string whereas real return type is resource.

Moreover, JSON serialization fails (I guess it's because it's quite difficult to json_encode a blob :))

Filter result using related table columns

How can I filter result using Related table columns?

Suppose We have 2 users(Admin1 and Admin2). A user can create/update a group.
When a user creates a group, we store user id as a foreign key in the groups table by name created_by.

Now I need to Fetch all groups created by admin1 using the user name column.

I dig deep in TDBM package code but I am not being able to find any Built-in functionality that can support this use-case.

Please let me know If I miss this functionality or I need to write a raw query for this use-case.

Oracle unit test fail all

Following merge of #43, Oracle unit test fail to build the schema.

Error message:

There were 147 errors:

1) TheCodingMachine\TDBM\Commands\GenerateCommandTest

Doctrine\DBAL\Driver\OCI8\OCI8Exception: ORA-00942: table or view does not exist in /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php:33

Stack trace:

#0 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php(350): Doctrine\DBAL\Driver\OCI8\OCI8Exception::fromErrorInfo(Array)

#1 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php(140): Doctrine\DBAL\Driver\OCI8\OCI8Statement->execute()

#2 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1094): Doctrine\DBAL\Driver\OCI8\OCI8Connection->exec('ALTER TABLE "re...')

#3 /app/tests/TDBMAbstractServiceTest.php(341): Doctrine\DBAL\Connection->exec('ALTER TABLE "re...')

#4 /app/tests/TDBMAbstractServiceTest.php(108): TheCodingMachine\TDBM\TDBMAbstractServiceTest::initSchema(Object(Doctrine\DBAL\Connection))

#5 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(668): TheCodingMachine\TDBM\TDBMAbstractServiceTest::setUpBeforeClass()

#6 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))

#7 /app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(517): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))

#8 /app/vendor/phpunit/phpunit/src/TextUI/Command.php(186): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)

#9 /app/vendor/phpunit/phpunit/src/TextUI/Command.php(116): PHPUnit_TextUI_Command->run(Array, true)

#10 /app/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()

#11 {main}

Next Doctrine\DBAL\Exception\TableNotFoundException: An exception occurred while executing 'ALTER TABLE "ref_no_prim_key" ADD CONSTRAINT FK_616AF5B76A5A3777 FOREIGN KEY ("from") REFERENCES ref_no_prim_key ("to")':

ORA-00942: table or view does not exist in /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php:58

Stack trace:

#0 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(176): Doctrine\DBAL\Driver\AbstractOracleDriver->convertException('An exception oc...', Object(Doctrine\DBAL\Driver\OCI8\OCI8Exception))

#1 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/DBALException.php(150): Doctrine\DBAL\DBALException::wrapException(Object(Doctrine\DBAL\Driver\OCI8\Driver), Object(Doctrine\DBAL\Driver\OCI8\OCI8Exception), 'An exception oc...')

#2 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1096): Doctrine\DBAL\DBALException::driverExceptionDuringQuery(Object(Doctrine\DBAL\Driver\OCI8\Driver), Object(Doctrine\DBAL\Driver\OCI8\OCI8Exception), 'ALTER TABLE "re...')

#3 /app/tests/TDBMAbstractServiceTest.php(341): Doctrine\DBAL\Connection->exec('ALTER TABLE "re...')

#4 /app/tests/TDBMAbstractServiceTest.php(108): TheCodingMachine\TDBM\TDBMAbstractServiceTest::initSchema(Object(Doctrine\DBAL\Connection))

#5 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(668): TheCodingMachine\TDBM\TDBMAbstractServiceTest::setUpBeforeClass()

#6 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))

#7 /app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(517): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))

#8 /app/vendor/phpunit/phpunit/src/TextUI/Command.php(186): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)

#9 /app/vendor/phpunit/phpunit/src/TextUI/Command.php(116): PHPUnit_TextUI_Command->run(Array, true)

#10 /app/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()

#11 {main}

Caused by

Doctrine\DBAL\Driver\OCI8\OCI8Exception: ORA-00942: table or view does not exist in /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php:33

Stack trace:

#0 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php(350): Doctrine\DBAL\Driver\OCI8\OCI8Exception::fromErrorInfo(Array)

#1 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/OCI8/OCI8Connection.php(140): Doctrine\DBAL\Driver\OCI8\OCI8Statement->execute()

#2 /app/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php(1094): Doctrine\DBAL\Driver\OCI8\OCI8Connection->exec('ALTER TABLE "re...')

#3 /app/tests/TDBMAbstractServiceTest.php(341): Doctrine\DBAL\Connection->exec('ALTER TABLE "re...')

#4 /app/tests/TDBMAbstractServiceTest.php(108): TheCodingMachine\TDBM\TDBMAbstractServiceTest::initSchema(Object(Doctrine\DBAL\Connection))

#5 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(668): TheCodingMachine\TDBM\TDBMAbstractServiceTest::setUpBeforeClass()

#6 /app/vendor/phpunit/phpunit/src/Framework/TestSuite.php(722): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))

#7 /app/vendor/phpunit/phpunit/src/TextUI/TestRunner.php(517): PHPUnit_Framework_TestSuite->run(Object(PHPUnit_Framework_TestResult))

#8 /app/vendor/phpunit/phpunit/src/TextUI/Command.php(186): PHPUnit_TextUI_TestRunner->doRun(Object(PHPUnit_Framework_TestSuite), Array, true)

#9 /app/vendor/phpunit/phpunit/src/TextUI/Command.php(116): PHPUnit_TextUI_Command->run(Array, true)

#10 /app/vendor/phpunit/phpunit/phpunit(52): PHPUnit_TextUI_Command::main()

#11 {main}

Cannot use find() with reserved keywords

Hello,

I have this code that is not working:

/**
     * @param int $idcompany_relationship
     * @param string $type
     * @param string|null $value
     * @return \Wabel\Entities\CompanyRelationshipHistory|null
     */
    public function getLastHistory($idcompany_relationship, $type, $value)
    {
        return $this->find("idcompany_relationship = :idcompany_relationship AND field = :field AND value_to :value_to", [
            "idcompany_relationship" => $idcompany_relationship,
            "field" => $type,
            "value_to" => $value,
        ], "history_date DESC")->first();
    }

But this one works well:

/**
     * @param int $idcompany_relationship
     * @param string $type
     * @param string|null $value
     * @return \Wabel\Entities\CompanyRelationshipHistory|null
     */
    public function getLastHistory($idcompany_relationship, $type, $value)
    {
        $lastId = $this->tdbmService->getConnection()->executeQuery('SELECT idrelationship_history FROM company_relationship_history WHERE idcompany_relationship = '.$idcompany_relationship.' AND field = "'.$type.'" ORDER BY history_date DESC LIMIT 1')->fetch();
        if (!$lastId) {
            return null;
        }
        return $this->findOne([
            'idrelationship_history' => $lastId
        ]);
    }

I'm thinking that field is a reserved word in MySQL, and the escape is not done properly.

Anything you can do ?

Thank you :)

Foreign keys with default values are not automatically initialized in constructors

Database : I have a table agreement and a table agreement_status
In my table agreement, i have a column status_id, referencing to the agreement_status with a default value of 1
In the agreement_status table, the line with id = 1 exists

Issue : in the constructor of the AbstractAgreement, the status is not automatically set, we have to provide it as a parameter. Indeed, the status must be an instance of AgreementStatus, and not simply a value, like 1
So right now, the default value is ignored

Solution : if the foreign key has a default value, the constructor should automatically find the object asscoiated to the default value, and set it in the constructor

Error when deleting bean with primary key on multiple columns

Hello,

I have a table participation with 3 columns:

  • event_code (varchar)
  • idcompany (int)
  • key (varchar)

My primary key is event_code AND idcompany.

When I try to delete a participation I have this error:

Doctrine\DBAL\Exception\InvalidArgumentException: Empty criteria was used, expected non-empty criteria

/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Exception/InvalidArgumentException.php:38
/var/www/html/vendor/doctrine/dbal/lib/Doctrine/DBAL/Connection.php:675
/var/www/html/vendor/thecodingmachine/tdbm/src/TDBMService.php:287

Is it a problem on my side ?

Thanks

TheCodingMachine\TDBM\TDBMService issues from php 7.4

we are using this package on php 7.4.
I noticed that the server returns 500 error with Notice: Trying to access array offset on value of type bool when I try to delete beans or return ResultIterator to jsonresponse.
This error doesn't always happen, I think this error happens when the bean has many_to_many relationships with other tables.

TDBM causes diff when regenerating DAOs (5.0.16)

Hello,

Maybe it's fixed on new version, but when generating DAOs, TDBM causes git to detect a diff even if table the structure didn't change, which makes unwanted changes hard to track !

Thx !

Improve DAOFactory performance

We can tremendously improve DaoFactory performance by lazy loading Daos.
To do that, it is easy to inject the container in the DaoFactory (rather than the dao instances), and to fetch the daos based on their names.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.