Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Instantiating specific models off a list findAll()

$
0
0
JMVC 3.2 here:

I'm wondering what the best method is when instantiating a list with different models extending off a base model class.

I have a Person base model class - Student model and Teacher model extend off Person. I have a People List class and would like to findAll() on the People List. How do I go about instantiating Students and Teachers from the People findAll() endpoint? Is this an anti-pattern?

My people.json structure:

[{ "name": "Chris", "age": 24, "type": "student" }, { "name": "Bill", "age": 50, "type": teacher" }]

I'm thinking I might need to do a list.each() in the list.findAll() function and then instantiate with a dynamic variable?

Something's telling me I might need to use "associations".

My apologies if that wasn't clear!

Viewing all articles
Browse latest Browse all 3491

Trending Articles