Menu

How I set Required property on a column?

Help
2014-06-13
2014-06-14
  • Felice Guarneri

    Felice Guarneri - 2014-06-13

    Hi, I want set Required property on some column and I read that it's possible but I not found how I can make it. Can someone explain me? Thanks!

     
  • Felice Guarneri

    Felice Guarneri - 2014-06-13

    I read it but I don't understand how I do write. Under there is an example, I want set required the column NAME, so after the creation of the table I set property how I think should do but... something is wrong

    Table table = new TableBuilder("People")
    .addColumn(new ColumnBuilder("ID",DataType.LONG).setAutoNumber(true))
    .addColumn(new ColumnBuilder("NAME",DataType.TEXT).setLengthInUnits(255))
    .addColumn(new ColumnBuilder("SURNAME",DataType.TEXT).setLengthInUnits(255))
    .toTable(database); table.getColumn("NAME").getProperties().put(PropertyMap.REQUIRED_PROP, DataType.TEXT, "");

     
  • James Ahlborn

    James Ahlborn - 2014-06-14

    The required property is most likely a boolean, so you probably want:

    .put(PropertyMap.REQUIRED_PROP, DataType.BOOLEAN, true);

     
  • Felice Guarneri

    Felice Guarneri - 2014-06-14

    Thanks, it work! Only a thing, after I put property, I had to do

    table.getColumn("NAME").getProperties().save();

    for effectively set into db the property.

     

Log in to post a comment.

MongoDB Logo MongoDB