View Full Version : HasOne or none (nullable) associations

26 Jul 2013, 2:13 AM
ExtJS provides us with different associations:

1 to 0 or more => hasMany
1 to 1 => hasOne

But how about the 1 to 0 or 1

dog = {
name: 'frank',
home: {
street: 'sesamestreet 5',
city: 'holland'

but the homeless dog has no home

homelessDog= {
name: 'fifi',
home: null


homelessDog= {
name: 'fifi'

If I load the data with no home in my model with a hasOne association, and I call getHome() I don't get null or undefined but an empty address model.

Why is that? Is it intended? How should I approach these kind of issues correctly?

Gary Schlosberg
2 Aug 2013, 7:48 AM
Looks like the empty address model is the intended behavior. If null or undefined were passed, it would try to load the associated data via the proxy defined on the model (error if undefined). A plain object allows one to get a blank model and check for data or perhaps an ID.

5 Aug 2013, 12:01 AM
You're right Gary. For a 1 to 1 relation it's logical. But a 1 to 0 or 1 relation it's far from ideal.. Like we say in Dutch, I guess we have to "row with the paddles we have".