# Any side effects to using custom topic archetypes?

**URL:** https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370
**Category:** Development
**Created:** [September 30, 2018, 12:25am UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370 "2018-09-30T00:25:51Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [September 30, 2018, 12:25am UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/1 "2018-09-30T00:25:51Z")

</div>

For a project I am working on, I am storing data as topics with their own special archetype. They’re not _really_ topics, the category and body don’t matter and the important information is held in custom fields. I went with this design to avoid dealing with database migrations and the like. This is a private plugin that won’t be disabled except during A/B testing. Are there side effects to this? Am I doing it completely wrong?

---

<div class="post-metadata">

### Author: ![erlend\_sh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/erlend_sh/32/119475_2.png) [@erlend\_sh](https://meta.discourse.org/u/erlend_sh)
#### Post date: [October 5, 2018, 11:30am UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/2 "2018-10-05T11:30:36Z")

</div>

Is your code open source? At the very least some actual code examples would go a long way here.

If the code works you’re probably not doing it _terribly_ wrong 😉

---

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [October 5, 2018, 2:42pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/3 "2018-10-05T14:42:43Z")

</div>

I can’t make the code open source right now for legal reasons, sorry…(the code isn’t on any public facing site right now either).

As for code examples, there’s not much to show. I `Archetype.register` in an initializer, then use the following:

```plaintext
TopicQuery.results_filter_callbacks << Proc.new do |_, result, user|
	result.where.not(archetype: 'the_archetype')
end

```

I then have the following guardian (with a TODO to fix the DRY):

```plaintext
	module FoobarGuardian
		def can_edit_topic?(topic)
			topic.archetype != 'the_archetype' && super
		end

		def can_create_post_on_topic?(topic)
			topic.archetype != 'the_archetype' && super
		end
	
		def can_create_post_on_topic?(topic)
			topic.archetype != 'the_archetype' && super
		end

		def can_see_topic?(topic)
			topic.archetype != 'the_archetype' && super
		end
	end

	require_dependency 'guardian/topic_guardian'
	::TopicGuardian.prepend FoobarGuardian

```

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [October 5, 2018, 5:36pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/4 "2018-10-05T17:36:59Z")

</div>

I’d be hesitant to create a new archetype value for that field. I’d be concerned that it might break code that was written with the assumption there would be only certain possible values. eg.

```plaintext
where topic archetype not equal to private message 

```

Might it not be better to work with topic custom fields?

---

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [October 5, 2018, 5:39pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/5 "2018-10-05T17:39:14Z")

</div>

> [@Mittineague](#):
>
> I’d be concerned that it might break code that was written with the assumption there would be only certain possible values

I was concerned about this as well, but built into Discourse is another archetype (I don’t remember, but I think it’s banner?) so this shouldn’t be the case. Everything I read uses `.private_message?` anyhow, which _may_ be making these assumptions I don’t want, though.

> [@Mittineague](#):
>
> Might it not be better to work with topic custom fields?

I do use custom topic fields, but these aren’t normal topics and shouldn’t be able to be accessed as such.

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [October 5, 2018, 5:53pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/6 "2018-10-05T17:53:35Z")

</div>

I just looked at this code. The word “default” suggests it should be OK to create non-default values

> <https://github.com/discourse/discourse/blob/main/lib/archetype.rb#L40-L45>

---

<div class="post-metadata">

### Author: ![Kampfkarren](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kampfkarren/32/109627_2.png) [@Kampfkarren](https://meta.discourse.org/u/Kampfkarren)
#### Post date: [October 5, 2018, 5:55pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/7 "2018-10-05T17:55:27Z")

</div>

I understand that, I’ve seen other plugins use it to create pseudo-topics, I’m just wondering if there’s any side effects to it that I should be aware of (e.g. that they show up in the topics list and I have to manually filter that out).

---

<div class="post-metadata">

### Author: ![Mittineague](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mittineague/32/114259_2.png) [@Mittineague](https://meta.discourse.org/u/Mittineague)
#### Post date: [October 5, 2018, 6:01pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/8 "2018-10-05T18:01:30Z")

</div>

> [@Kampfkarren](#):
>
> wondering if there’s any side effects

I think that will depend on how the conditionals are written. There is a not always so obvious difference between “is regular” and “is not private message”.

I’m assuming that Core Discourse code is written correctly. What would be more a possible problem is third party code.

---

<div class="post-metadata">

### Author: ![david](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/david/32/157490_2.png) [@david](https://meta.discourse.org/u/david)
#### Post date: [October 5, 2018, 9:23pm UTC](https://meta.discourse.org/t/any-side-effects-to-using-custom-topic-archetypes/98370/9 "2018-10-05T21:23:14Z")

</div>

The only case I know if where a custom archetype has been used is Babble, and I know that has taken a LOT of development and maintenance work over the years.

> [@Kampfkarren](#):
>
> They’re not _really_ topics, the category and body don’t matter and the important information is held in custom fields.

If they’re not really topics, maybe you would be better off with using the PluginStore system. As @erlend_sh said it’s very hard to give advice if we don’t know what you’re trying to achieve.
