Skip to content

Support more type and relationship #4

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

Open
ele828 opened this issue Sep 7, 2016 · 5 comments
Open

Support more type and relationship #4

ele828 opened this issue Sep 7, 2016 · 5 comments

Comments

@ele828
Copy link
Member

ele828 commented Sep 7, 2016

Typescript can not support complex type reflection, I consider supporting it by this way:

@Entity()
class Person extends Model {

  @Column()
  @OneToMany(type => Person, person => person.id)
  friends: Person[];

}
@ele828 ele828 assigned lucklove and unassigned lucklove Oct 31, 2016
@ele828
Copy link
Member Author

ele828 commented Oct 31, 2016

Cauz for now, Typescript doesn't support complex type reflection. The only way to handle this issue is to support Types and Relationships in Decorators, it looks like:

@Entity(alias?)
class Foo {
    @Column(alias? | Type?)
    bucket: Type;
}

This is really important, only when we finish this, the Torm.js can be used. This is the core features of Torm.js.

@yfwz100
Copy link
Contributor

yfwz100 commented Oct 31, 2016

Firstly,

@OneToMany(type => Person, person => person.id)

Don't know what you mean in the example. person.id seems to refer to a undefined object person. It's not a correct syntax.

Why not try

@OneToMany(type => Person, person => "id")

And you mention @Column(alias? | Type?), what's the meaning of alias and type? I see that type definition is given by variable definition.

@ele828
Copy link
Member Author

ele828 commented Oct 31, 2016

@yfwz100 yeah. you're right! What I want to do here is to set a foreign key.

@Column(alias? | Type?) This means the first argument can be Alias or Complex Type. Some types like float double (we don't have this in JS) or customized Type cannot be reflected for now in Typescript. Do you have any better ideas for this?

@yfwz100
Copy link
Contributor

yfwz100 commented Nov 1, 2016

Got the idea. In Mongoose-like ORM in javascript, the complex type is modeled as a new class. I think we can adopt this. The drafted syntax could be like

@Column(type=Float, alias="col_name")

where Float is a custom class defined by us (so it should be imported before used). The idea of using custom type instead of raw string is to facilitate the development with syntax check at compile time.

@ele828
Copy link
Member Author

ele828 commented Nov 1, 2016

@yfwz100 , that's exactly what I want

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

3 participants