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

Can't get the example to work #22

Open
JanHolger opened this issue May 23, 2019 · 1 comment
Open

Can't get the example to work #22

JanHolger opened this issue May 23, 2019 · 1 comment

Comments

@JanHolger
Copy link

I tried to copy & paste the example code, from the README and only changed the db credentials.
I get the following error:

../../.dub/packages/hunt-validation-0.1.1/hunt-validation/source/hunt/validation/DeclDef.d-mixin-40(42,52): Error: function `app.User.MakeModel!().MakeValid!().valid` does not override any function
../../.dub/packages/hunt-entity-2.3.4/hunt-entity/source/hunt/entity/Entity.d(25,5): Error: mixin `app.User.MakeModel!().MakeValid!()` error instantiating
source/app.d(6,5): Error: mixin `app.User.MakeModel!()` error instantiating

My dub.json:

{
	"dependencies": {
		"hunt-database": "~>1.2.0",
		"hunt-entity": "~>2.3.4"
	},
	"name": "test",
	"targetName": "test",
	"targetPath": "bin",
	"targetType": "executable"
}

My dmd version is: v2.085.1

I already tried to find the reason for this error on my own but I just started learning d-lang an hour ago so i'm not that experienced enough to really understand that error.

@ktm5j
Copy link

ktm5j commented Jul 17, 2019

I just hit the same problem and found this issue via google.. from looking at the examples in the examples/ directory it looks like the User class needs to extend hunt.entity.Model

so the class should look like this, adding : Model to the declaration:

@Table("user")
class User : Model
{
    mixin MakeModel;
...
}

After fixing that I'm still unable to compile however.. dub build tells me that there's no log(...) function. But after including hunt.logging I can find logDebug() which seems to work.

So here's my modified source that compiles successfully:

import hunt.entity;
import hunt.logging;

@Table("user")
class User : Model
{
    mixin MakeModel;

    @PrimaryKey
    @AutoIncrement
    int id;

    string name;
    double money;
    string email;
    bool status;
}

void main()
{
    auto option = new EntityOption;

    option.database.driver = "postgresql";
    option.database.host = "...";
    option.database.port = 5432;
    option.database.database = "...";
    option.database.username = "...";
    option.database.password = "...";
    option.database.prefix = "hunttest_";

    EntityManagerFactory entityManagerFactory = Persistence.createEntityManagerFactory("postgresql", option);
    EntityManager em = entityManagerFactory.createEntityManager();

    // begin transaction
    em.getTransaction().begin();

    // define your database existing row id in here
    int id = 1;

    auto user = em.find!User(id);
    logDebug("User name is: ", user.name);

    // commit transaction
    em.getTransaction().commit();

    em.close();
    entityManagerFactory.close();
}

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