Reputation: 1
I'm new to Smalltalk and i have this question.
I have written this message:
((Objednavkaset select:[:a | a auto porucha notEmpty])
select: [:d |
(d auto porucha select:[:x |
x datum_poruchy
between: x datum_vypujceni
and: x datum_skutecneho_vraceni])
size > 0])
and I have this problem, i need to access datum_vypujceni
and datum_skutecneho_vraceni
from this select
select: [:d | (d auto porucha select:[:x | x datum_poruchy between: x datum_vypujceni and: x datum_skutecneho_vraceni]]
but I don't know how, is there any way to access it?
Here is diagram if you need it.
Upvotes: 0
Views: 241
Reputation: 22290
I'll edit as you clarify what you're really after, but I can provide this much so far...
I think your first level select:
makes it harder to see things. Using anySatisfy:
will automatically filter out the empty ones.
Objednavkaset select: [:eachSet |
eachSet auto porucha anySatisfy:[:eachPorucha |
eachPorucha datum_poruchy
between: x datum_vypujceni
and: x datum_skutecneho_vraceni]]
Upvotes: 0
Reputation: 948
As the innermost condition is
x datum_poruchy
between: x datum_vypujceni
and: x datum_skutecneho_vraceni
everything is part of the x object, so the whole condition should be there, like
hasValidPoruchy
^datum_poruchy
between: datum_vypujceni
and: datum_skutecneho_vraceni
Upvotes: 2
Reputation: 15917
In your method you use a auto porucha
and d auto porucha
. That long chain suggests that some behavior might not be defined on the right object. The "Law of Demeter" suggests to reduce those chains, e.g. by defining on the object this auto refers to what the porucha anySatisfy:...
actually are
Upvotes: 1
Reputation: 14843
As much as I like Uko's answer for the removal of the initial select:
and the use of anySatisfy:
, I think that Jarda's question still remains unanswered.
The actual question is how to access the two instance variables datum_vypujceni
and datum_skutecneho_vraceni
of objed
, rather than how to write the selection script.
So, here is the answer to this simple question: Jarda, add two methods in your Objednavka
class that answer these instance variables:
datum_vypujceni
^datum_vypujceni
datum_skutecneho_vraceni
^datum_skutecneho_vraceni
Once you have these methods, your script will get these data from your objed
variable. Note also that you will need another getter to access the datum_poruchy
of a Poruchy
. So make sure your Poruchy
class has the getter method
datum_poruchy
^datum_poruchy
Upvotes: 3
Reputation: 13396
What is your goal? If you want to get all Objednavka that has at least one Poruchy that has date between other dates of the Objednavka it belongs to, you can do it like this:
(Objednavkaset select: [ :objed |
objed auto porucha anySatisfy: [ :poruchy |
poruchy datum_poruchy
between: objed datum_vypujceni
and: objed datum_skutecneho_vraceni ] ] ]
also I don't know if your smalltalk has #anySatisfy:
. If not - let me know. If you code in pharo, it definitely has
Upvotes: 2