Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Recursive field (Number of children)

Featured Replies

Hi,

 

Let say I want to create a blog in which user can add comments. Each comment can also be commented.

 

I want to create a field that calculates the total number of comments a blog or a comment has.

 

Here is the tables structure

 

Blogs (id, article, c_nbComments...)

Comments (id, id_blogid_parentComment, comment, c_nbComments, ...)

 

Let say I have two groups of Anchor-buoy

BL__BLOGS --< bl_COMMENTS

 

CMT__COMMENTS --< cmt_COMMENTS__children

 

So how can I calculate the total number of comments for each blog or comments?

 

Thanks

 

 

In FM 12, you'd be able to whip up a SQL query in a case statement and have at it fairly easily. In FM 11, if your calculation is being stored in c_nbComments, do this:

 

In Blogs:

Count(bl_COMMENTS::id) + Sum(bl_COMMENTS::c_nbComments)

 

In Comments (evaluate this from the context of CMT_COMMENTS): 

Count(cmt_COMMENTS__children::id) + Sum(cmt_COMMENTS__children::c_nbComments)

 

That will give you the totals you want, though it might be a little slow if you're talking about very large numbers of nested comments

  • Author

I have tried the FM11 method before posting, it was the exact suggestion you put, but the results were not good...

 

My SQL is quite rusty. Do you have a quick query? :)

 

Thanks

  • Author

D'uh... using the FM11 method I used sum twice instead of a count and a sum.

 

I am still looking at how to do it using SQL.

 

For the comments, I have tried something similar to this, but FM doesn't seem to be able to parse it.

WITH    q AS
(
	SELECT  id, id_parentComment
	FROM    CMT_COMMENTS
	UNION ALL
	SELECT  p.id, p.id_parentComment
	FROM    q
	JOIN    CMT_COMMENTS p
	ON      p.id = q.id_parentComment
)
SELECT  id, COUNT(*)
FROM    q
GROUP BY id
  • Author

I have managed to create an hybrid calculation (FM + executeSQL), but I'm still looking for a full SQL calculation.

 

Here I attached a very simplified version of what I would like to accomplish.

 

Thanks for helping

recursion.zip

Sorry, upon further review I realized that Filemaker doesn't seem to support true SQL recursion syntax, so you'd have to use SQL in a recursive custom function. Otherwise, the unstored calculated fields are probably the best way to go.

  • Author

Ok, thanks!

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.