Skip to content

Conditionally ignore column on insert or update? #48

@bdcodestuff

Description

@bdcodestuff

Hi,

Thanks for the great library, I'm enjoying using it.
I'm struggling with something that seems like it should have an obvious answer.
When I define a model describing a one-to-many relationship through a foreign-key, in the parent class I include a column definition to catch all the children items in a List structure. So imagine backing models like this:

[Table("user")]
public class User : BaseModel
{
    [PrimaryKey("id", false)]
    public int Id { get; set; }

    [Column("name")]
    public string Name { get; set; }

    [Column("created_at")]
    public DateTime CreatedAt { get; set; }

    [Column("intervention")]
    public List<Intervention> Interventions { get; set; }
}

[Table("intervention")]
public class Intervention : BaseModel
{
    [PrimaryKey("id",false)]
    public int Id { get; set; }

    [Column("description")]
    public string Description { get; set; }

    [Column("created_at")]
    public DateTime CreatedAt { get; set; }
}

Querying the user table using :

var users = await client.Table<User>() .Select("*,intervention(*)") .Get();

This works great with anticipated automatic population of the User's "Interventions".

The problem is that if I try to Insert a new User or Update an existing User with these models it complains that there is no column matching "intervention".

So I'm wondering if it's possible to have something similar to how the PrimaryKey attribute works, but broaden it so that any Column attribute includes the option to specify shouldInsert and shouldUpdate boolean flags. If those are set to false the column is ignored when writing to the DB, but included in the model during reads.

There may also be a better solution that I'm missing entirely. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions