How to make a conditional parent link

Hi,

Say I have a BillPlanning and MonthlyPaiement types, for one BillPlanning, there could be many monthlyPaiements linked to. a BillPlanning parent field in monthlyPaiements and a list field in BillPlanning made it possible.

entity type BillPlanning  {
 id : string // is unique
  monthlyPaiements: [MonthlyPaiement](parent)
  echeanceCount : int
 }

entity type MonthlyPaiement {
parent                    : BillPlanning
echeanceCount      : int
}

Now what I want to achieve, is to detach this link for some monthlyPaiements objects, knowing a specific values field.
say when MonthlyPaiement#echeanceCount == BillPlanning#echeanceCount

I don’t want to alter BillPlanning ids definition.
Is there a C3 way to do this? or any conception idea, it is very welcome.

ps: Otherwise, I may achieve this programmatically.
Many thanks.

You can make a calc field on the BillPlanning type that looks something like this:

subsetOfPaiements: [MonthlyPaiement] stored calc "monthlyPaiements.echeanceCount == echeanceCount" schema suffix "EQ_COUNT"

this will store an array of MonthlyPaiements that match the condition. Note that you may not want to store it, depending on how many MonthlyPaiements could be in the list and how often the field may be referenced.

Here’s a bit more details in this post: Creating a filtered collection field on a type

Thank you for replying! Appreciate it.
Another question, how to only filter on children?
also, it didn’t compile: returning:
project/C3Type/BillPlanning.c3typ [16,50] E extraneous input 'expression' expecting STRING
But successfully provisioned without ‘expression’ on C3 7.6.

updated the syntax, it should compile now. Other examples of syntax can be found here: Implement stored calc based on another stored calc

Thanks for posting, and I hope you continue to enjoy poking around here, there’s a lot of great content and examples to be discovered!

Using:
currentPaiements: [MonthlyPaiement] stored calc "monthlyPaiements.echCount == totalNumberEch && monthlyPaiements.parent.id == id" schema suffix "BQ_COUNT"
didn’t work for currentPaiements. although monthlyPaiements does :frowning:

This stored calc would return a boolean. I think what you might want is:

monthlyPaiements.(echCount == totalNumberEch && parent.id == id)

@AlexBakic suggested
currentPaiements: [MonthlyPaiement](parent) stored calc "monthlyPaiements.echCount == totalNumberEch" schema suffix "EQ_COUNT" instead of simple:

currentPaiements: [MonthlyPaiement] stored calc "monthlyPaiements.echCount == totalNumberEch && monthlyPaiements.parent.id == id" schema suffix "BQ_COUNT"

So Alex’s suggestion worked finaly.

I would like to try you suggestion @sean.summers later.
Many thanks.

You should be able to replace parent.id == id by (parent) in the second field declaration, too. Then, probably also refer to currentPaiements instead of monthlyPaiements in the second field declaration. I am fine with either if they work for you, but it seems to me that the two fields are not interdependent, so adding a dependence may be confusing. Or I got it all wrong :sweat_smile:

However, make sure that you do not lose some objects if you only search them in these two fields.