Deleting un-referenced items

Answered

Comments

4 comments

  • [100Rails] Steve Shepherd

    Jonathan, you need to be careful with this as you are doing a form of referential integrity (as it used to be called) but Podio is more of a Object relational model.
    Even if an object is deleted recording that it was attached at some point to another app item is a valid use case in some situations.
    You could use the app ref item returned to then make another call with a GET and check for an error return. You will burn through api calls however...

    0
    Comment actions Permalink
  • Jonathan Sala

    @Steve I don't think I explained myself well enough.

    Basically we have a large number of items in an app which were imported badly. All items in this app should be referenced from app reference fields in other apps. If they're not referenced by any other items, then they're unneeded and so should be deleted to remove clutter.

    What I want to do is look at each item, see if any other items in other apps are linking to it from an app reference field, and if it is completely 'orphaned' (i.e. not linked to), delete it. I can't seem to work out a way to do this without a get call for every item in the app, as the information I need (references) is not included in filter responses.

    0
    Comment actions Permalink
  • Andreas Garnæs

    Hi Jonathan,

    You're right that you cannot filter items by "does any other items reference this". What you can do, though, is to use the refs property on an item, which is the number of other items referencing this item (it will thus be 0 if no other items reference it). This property is not included by default, so you need to specify that you'd like it to be included. To do so, pass in array("fields" => "refs") as the options-argument to PodioItem::filter.

    Best,
    Andreas

    1
    Comment actions Permalink
  • Jonathan Sala

    Hi Andreas,

    I didn't realise you could request specific properties in filter! Fantastic, thank you. Makes life much easier!

    0
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk