Enforcing cardinality: possible?

I build databases for law firms doing mass tort litigation. The main table is almost always something called “Clients”. I’m working on one right now in Knack. Because the Clients table is often pretty wide, I decided to separate data relating to the client’s lawsuit (case filed, etc.) from data relating to the client personally (address, phone, etc). So I created a table ClientCaseInfo and related it to Clients one-to-one.

image

The problem is: What does this setting mean? I was just working in the ClientCaseInfo table (where the connection above was defined) and I had no trouble creating a second case-info record for a client that already has one. I’d have expected that Knack would prevent me from doing this… Any suggestions or thoughts?

Hi William - Thanks for sharing your use case here when posting the question.

What you found to be true is unfortunately a limitation with the way our connections currently work. While the relationship between these objects is 1:1, we are not actually enforcing that the connected record can only be used once (this is a valid feature request that we have on our radar).

What we’ve seen work for some users, is to build in some functionality to the live app, via page rules, to prevent your live app users from creating an additional connected record.

While it is not intuitive, you would need to change your connection field to one-to-many (one Client to many ClientCaseInfo’s) and then add a count field to the parent Client object. After you’ve got a count field, you can use that value to hide views using page rules. So for example, if you are looking at a details page of the Client, you would hide the form that inserts a ClientCaseInfo if the count field is greater than 0.

Others may have other ideas. You can look for existing topics such as this for ideas: Enforce Uniqueness/Prevent Duplicates

Hope that helps!

1 Like

Jessie,

Thanks for the response and for the suggestion about a workaround. That would probably do. And for what it’s worth, this wouldn’t be easy to do in any of the other platforms that I’m familiar with.

William

1 Like

Hey @WilliamPorter and @Jessie - I saw your post but didn’t get time to come back to you on this one :stuck_out_tongue_closed_eyes: - Jessie beat me to it.

I concur, this is how I would do it. I don’t think I’ve ever used a 1-to-1 relationship in Knack.

I think the count option will work as along as you don’t have multiple users adding records at EXACTLY the same time. In which case you’ll need to use Julian’s JavaScript check for duplicates that Jessie referenced.

Hope it’s all going well and you’re enjoying the build :+1:

1 Like